If Statements - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: If Statements (/thread-9527.html) |
If Statements - Constantin - Apr-14-2018 Hello Python Users, I have started coding a few days ago and I want to write a code where it asks what age you are(for example 15) and it gives you the name you assigned the number 15 to. The problem is that I have no clue how to start... would anyone be kind enough to help me? ;) Thank you RE: If Statements - vaison - Apr-14-2018 Hello, My English level is low, and maybe I don't understand well, but if you want to read from keyboard, the basic form can be: print("How old are you?") age = input()Bye RE: If Statements - Constantin - Apr-14-2018 (Apr-14-2018, 08:33 PM)vaison Wrote: Hello, Yes thank you, this is good but I was thinking of input = ("How old are you?") | Then you write (for example) 12 and a Name comes out. I need to assign the numbers to the name. I just don't know how I do these two steps. RE: If Statements - IAMK - Apr-14-2018 if age == 1: print("Bob") elif age == 2: print("Putin")Alternatively, you could google "Python if statement" for an explanation of how if statements work. RE: If Statements - Larz60+ - Apr-14-2018 Constantin - I suggest you start with a tutorial where you will learn fast. One of my favorites is: https://www.python-course.eu/ RE: If Statements - vaison - Apr-15-2018 Hello, maybe, an other option is to use dictionaries: name_age = {1: "Bab", 15: "Beb", 30: "Bib"} age_in = input() name = name_age[int(age_in)] print(name)The dictionary should contain all the names and ages you want to contemplate It depends of what you want to do. RE: If Statements - wavic - Apr-15-2018 Sounds like homework. |