How to: save your name in a variable
I am a beginner and my teacher has told me to do some basic coding and I have forgotten how he did it. Can someone please help me out?
Okay. So, you've done good so far. input() asks the thing in parentheses. Since you say name = input("Foyjur"), foyjur is the question asked. You might want to do something like this:
name = input("Enter your name: ") print("Welcome " + name)
- Save your name in a variable
- Print a string along with your name using concatenation. Eg: Welcome Muhammad
- Ask for your age and store it in a variable
- Tell you your name is... and you are ... years old.
Create a program that asks for your name and stores it in a variable.
Then asks for your age and stores that in a variable too.
After that, it should do a calculation and see how many years until you can drive.
Then print the name and years left till you can drive.
Now I kinda feel bad for asking you for this many favours but you don't have to do all of the things if you don't want to.
My teacher doesn't explain the work properly for beginners like me so he just forgets about us and expects us to complete all the assignments he gives us.
Thanks for the help.
name = input("what is your name? ")
Now you use the + operator to add two strings together in the print()
print("Welcome " + name)
Now, when someone inputs an age, you immediately cast it to an int
age = int(input("What is your age? "))
Then you add it all together. Remember to cast the age back to a string when using the + operator
print("Hello " + name + ". You are " + str(age) + " years old.")
And that's it!