Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If Statements
#1
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
Reply
#2
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
Reply
#3
(Apr-14-2018, 08:33 PM)vaison Wrote: 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

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.
Reply
#4
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.
Reply
#5
Constantin - I suggest you start with a tutorial where you will learn fast.
One of my favorites is: https://www.python-course.eu/
Reply
#6
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.
Reply
#7
Sounds like homework.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020