Flash Sale: Flat 70% + Addl. 25% Off on all Courses | Use Coupon DS25 in Checkout | Offer Expires InEnroll Now
If you want to take the value for a variable from the user via their keyboard, Python provides a built-in function called
input that gets input from the keyboard. When this function is called, the program stops and waits for the user to type something. When the user presses
Enter, the program resumes and input returns what the user typed as a
inp = input()
It is a good thing to display to the user to enter what you want before taking the input.
name = input('What is Cloudxlab?\n')
\n at the end of the prompt represents a newline, which is a special character that causes a line break. That's why the user's input appears below the prompt.
If you expect the user to type an integer, you can try to convert the return value to
int using the
question = 'What is 2 multiplied by 3?\n' answer = input(question) print(int(answer))
It takes the answer from the user and prints it after converting it into
int. Try it in the notebook.
Input something other than a string of digits and observe the error that you get. (We will learn how to handle this kind of error later.)
input_namethat displays a prompt,
"What am I studying?"
Pythonafter the prompt.
No hints are availble for this assesment
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here