How to get like this output???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to get like this output????

using if statement i want syntax of if and elif If the first letter is A in our input it will select the A column if the first letter is B in our input it will select the B column sample output: ENTER YOUR NAME. : ABILASH YOUR ADJECTIVE NAME IS : ANGRY_ABILASH ENTER YOUR NAME. : BALAJI YOUR ADJECTIVE NAME IS : BOUNCER_BALAJI......

14th Sep 2018, 9:58 AM
ஹரி ராமநாதன்
ஹரி ராமநாதன் - avatar
3 Answers
14th Sep 2018, 11:43 AM
ஹரி ராமநாதன்
ஹரி ராமநாதன் - avatar
+ 8
This? name = input("ENTER YOUR NAME.: ").upper() print(name) if name[0] == "A": print(f"YOUR ADJECTIVE NAME IS: {word}_ABLE") elif name[0] == "B": print(f"YOUR ADJECTIVE NAME IS: {word}_BIG") elif name[0] == "C": print(f"YOUR ADJECTIVE NAME IS: {word}_CRAZY") elif name[0] == "D": print(f"YOUR ADJECTIVE NAME IS: {word}_DARING") But this is shorter: words = [ "ABLE", "BIG", "CRAZY", "DARING" ] name = input("ENTER YOUR NAME.: ").upper() print(name) for word in words: if word[0] == name[0]: print(f"YOUR ADJECTIVE NAME IS: {word}_{name}") You may have to format the input differently if this is homework 😉
14th Sep 2018, 11:12 AM
David Ashton
David Ashton - avatar
+ 2
I guess you are looking for sometbing like this? Inp = input().upper() first = inp[0] if first == "A": print("blabla") elif first == "B" and so on
14th Sep 2018, 11:03 AM
davy hermans
davy hermans - avatar