0
the meaning
age_input = input("Enter your age (default is 20): ") age = int(age_input) if age_input else 20 print("Your age is:", age)
2 Réponses
+ 4
Gift Ngambi,
if you are interested in python, i would recommend you to start with the `introduction to python` tutorial.
here some hints what the lines of code are doing:
*first line*: > an input is requested with a user prompt. the input is stored in the variable `age_input`. (data type of the input is string by default).
*second line*: > a special kind of conditional expression (ternary) is used to check if `age_input` is not empty. in this case `age_input` will be converted to an integer value and stored to variable `age`.
(in case of `age_input`contains characters other than digits, an error will happen in this step. an exeption of type `ValueError` is raised.)
if `age_input` is empty (user has just pressed only the return key), the value of 20 will be assigned to variable `age`.
*third line*: > the output will be done using print() function with a string and the variable `age`
+ 2
Gift Ngambi ,
Please remove the <button> tag and add a python tag, since your code snippet is in Python.
There are 3 statements. Do you understand some of them or none of them? If some, which part don't you understand? If none, maybe you should take Introduction to Python.