Fully Automatic Vending machine

Fully automatic vending machine coding question for tcs nqt 2020

TCS Coding Question Day 3 Slot 1 – Question 1

This is one of the previous year coding question of TCS NQT, which was held in October. The difficulty level of this question ranges from medium to high, so we would suggest that you should go through this question thoroughly

FULLY AUTOMATIC VENDING MACHINE

Problem Statement

FULLY AUTOMATIC VENDING MACHINE – dispenses your cuppa on just press of button. A vending machine can serve range of products as follows:

Coffee

  1. Espresso Coffee
  2. Cappuccino Coffee
  3. Latte Coffee

Tea

  1. Plain Tea
  2. Assam Tea
  3. Ginger Tea
  4. Cardamom Tea
  5. Masala Tea
  6. Lemon Tea
  7. Green Tea
  8. Organic Darjeeling Tea

Soups 

  1. Hot and Sour Soup
  2. Veg Corn Soup
  3. Tomato Soup
  4. Spicy Tomato Soup

Beverages

  1. Hot Chocolate Drink
  2. Badam Drink
  3. Badam-Pista Drink

Write a program to take input for main menu & sub menu and display the name of sub menu selected in the following format (enter the first letter to select main menu):

Welcome to CCD 

Enjoy your

Example 1:

  • Input:
    • c
    • 1
  • Output
    • Welcome to CCD!
    • Enjoy your Espresso Coffee!

Example 2:

  • Input
    • t
    • 9
  • Output
    • INVALID OUTPUT!

Day 2 Slot 2 Question 1

Click on the below button to study Day 2 Slot 2 Question 1 of TCS NQT Coding 2020 exam

Code

TCS Coding Questions

Click on the below button to study more TCS Coding Question

TCS Coding Question

4 comments on “Fully Automatic Vending machine”


  • Arun Kumar

    AS EASY AS IT GETS

    c = ‘c’
    i = 4
    menu = [[‘Espresso Coffee’,’Cappuucino Coffee’,’Latte Coffee’], [‘Plain Tea’,
    ‘Assam Tea’,’Ginger Tea’,’Cardamom Tea’,’Masala Tea’,’Lemon Tea’,’Green Tea’,
    ‘Organic Darjeeling Tea’], [‘Hot and Sour Soup’,’Veg Corn Soup’,’Tomato Soup’,
    ‘Spicy Tomato Soup’], [‘Hot Chocolate Drink’, ‘Badam Drink’,
    ‘Badam-Pista Drink’]]
    items = “ctsb”
    try:
    print(menu[items.index(c)][i-1])
    except:
    print(“INVALID OUTPUT!”)


  • Abhishek

    ………………………..THE FOLLOWING CODE ONLY RUN TEST CASE IN TCS EXAM………………………BY ABHISHEK PATIL
    n=str(input())
    m=str(input())
    if n==”T” and int(m)>=int(“9”):
    print(“INVALID OUTPUT!”)
    if n==”C” and int(m)>=int(“4”):
    print(“INVALID OUTPUT!”)
    if n==”S” and int(m)>=int(“5”):
    print(“INVALID OUTPUT!”)
    if n==”B” and int(m)>=int(“4”):
    print(“INVALID OUTPUT!”)
    if n==”C” and m==”1″:
    print(“Welcome to CCD!\nEnjoy your Espresso Coffee!”)
    if n==”C” and m==”2″:
    print(“Welcome to CCD!\nEnjoy your Cappuccino Coffee!”)
    if n==”C” and m==”3″:
    print(“Welcome to CCD!\nEnjoy your Latte Coffee!”)
    if n==”T” and m==”1″:
    print(“Plain Tea”)
    if n==”T” and m==”2″:
    print(“Assam Tea”)
    if n==”T” and m==”3″:
    print(“Ginger Tea”)
    if n==”T” and m==”4″:
    print(“Cardamom Tea”)
    if n==”T” and m==”5″:
    print(“Masala Tea”)
    if n==”T” and m==”6″:
    print(“Lemon Tea”)
    if n==”T” and m==”7″:
    print(“Green Tea”)
    if n==”T” and m==”8″:
    print(“Organic Darjeeling Tea”)
    if n==”S” and m==”1″:
    print(“Hot and Sour Soup”)
    if n==”S” and m==”2″:
    print(“Veg Corn Soup”)
    if n==”S” and m==”3″:
    print(“Tomato Soup”)
    if n==”S” and m==”4″:
    print(“Spicy Tomato Soup”)
    if n==”B” and m==”1″:
    print(“Hot Chocolate Drink”)
    if n==”B” and m==”2″:
    print(“Badam Drink”)
    if n==”B” and m==”3″:
    print(“Badam-Pista Drink”)


  • chandan

    a=input()
    b=int(input())
    dict = {
    ‘c’: [“Espresso Coffee”,”Cappuccino Coffee”,”Latte Coffee”],
    ‘t’: [“Plain Tea”,”Assam Tea”,”Ginger Tea”,”Cardamom Tea”,”Masala Tea”,”Lemon Tea”,”Green Tea”,”Organic Darjeeling Tea”],
    ‘s’: [“Hot and Sour Soup”,”Veg Corn Soup”,”Tomato Soup”,”Spicy Tomato Soup”],
    ‘b’: [“Hot Chocolate Drink”,”Badam Drink”,”Badam-Pista Drink”]
    }

    if a==’c’ or a==’t’ or a==’s’ or a==’b’:
    if b in range(len(dict[‘c’])):
    print(“Welcome to CCD!”)
    print(f”Enjoy your {dict[a][b-1]}!”)
    else:
    print(“INVALID INPUT!”)
    else:
    print(“INVALID INPUT!”)
    #Dictionaries makes it much easier in these types of qs#


  • Technophilic

    menu={“c”:[“Espresso Coffee”,”Cappuccino Coffee”,”Latte Coffee”],”t”:[“Plain Tea”,”Assam Tea”,”Ginger Tea”,”Cardamom Tea”,”Masala Tea”,”Lemon Tea”,
    “Green Tea”,”Organic Darjeeling Tea”],”s”:[“Hot and Sour Soup”,”Veg Corn Soup”,”Tomato Soup”,”Spicy Tomato Soup”],”b”:[“Hot Chocolate Drink”,”Badam Drink”,
    “Badam-Pista Drink”]}
    men=input()
    val=int(input())
    if men in menu:
    for i in menu:
    if i==men:
    if val in range(len(menu[i])+1):
    print(“Welcome to ccd”)
    print(“Enjoy your {0}!”.format(menu[i][val-1]))
    else:
    print(“Invalid input”)
    else:
    print(“Invalid input”)