favoriteColor = input('What is your favorite color? ')
print('Your favorite color is', favoriteColor)
Get DetailedExplanations
When the assignment statement runs, the following steps happen in order:
1. The prompt string is printed to the Shell.
2. The program stops and waits for the user to type a response.
3. The user enters some sequence of characters into the Shell as an answer.
4. When the user presses the Enter key (Windows) or the Return key (Mac), input returns the characters that the user typed.
5. Typically, input is used on the right-hand side of an assignment statement. The user’s response is stored into the variable on the left-hand side of the equals sign.
Floating BuddyCode Editor - Click-n-Drag
Don't MissImportant Information
Note: The input function in Python returns all the characters that the user types, as a string.
Hundreds ofInteractive Exercises
Try Yourself Problems & Solutions
Try Yourself
Ask for the user’s first name and then ask for their surname and display the output message
Hello [First Name] [Surname].
Solution
firstname = input ("Please enter your first name: ")
surname = input ("Please enter your surname: ")
print ("Hello",firstname,surname)
Challange Problems & Solutions
Problem
Take name, roll number and field of interest from user as inputs and print in the below format:
Hey, my name is [name] and my roll number is [roll number]. My field of interest is [interest]
Solution
name=input("Enter name: ")
roll=input("Enter roll number: ")
interest=input("Field of interest: ")
print ("Hey, my name is",name,"and my roll number is",roll,". My field of interest is",interest)
Assuming you entered name = David, roll = 123 and interest = Coding
"Hey, my name is David and my roll number is 123. My field of interest is Coding
Earn PyStrikePoints, Badges & Ranks
In addition to all the above benefits, you will get PyStrike Awards in the form of Points, Badges and Ranks as explained below:
PyStrike Points
XPs
100 XPs for enrolling into the Embark Course.
10 XPs for daily logging into the PyStrike.com website.
Bolts
1 Bolt for securing 1 mark in each interactive exercise.
Strikes
10 Strikes for completing each Lesson.
PyStrike Badges
Learner
You will earn the “Learner” Badge and 50 “Strikes” on fulfilling the following requirements:
Reach a balance greater or equal to 50 Bolts, and
Pass the Quiz-Getting Started.
Achiever
You will earn the “Achiever” Badge and 20 “Strikes” on fulfilling the following requirements:
Already earned the “Learner” Badge, and
Reach a balance greater or equal to 70 Bolts, and
Pass the Quiz-Functions.
Scholar
You will earn the “Scholar” Badge and 20 “Strikes” on fulfilling the following requirements:
Already earned the “Achiever” Badge, and
Reach a balance greater or equal to 90 Bolts, and
Pass the Quiz-Flow Of Control.
Leader
You will earn the “Leader” Badge and 60 “Strikes” on fulfilling the following requirements:
Already earned the “Scholar” Badge, and
Reach a balance greater or equal to 150 Bolts, and
Pass the Quiz-Data Structures.
PyStrike Ranks
Neo
All new recruits will be awarded the Rank of “Neo”.
Whiz
Earn the “Achiever” Badge to rise to the Rank of Whiz”.
Star
Earn the “Leader” Badge to rise to the Rank of “Star”.
Get Course CompletionCertificate
Celebrate and share your achievement with others through Certificate of Completion on successfully completing the course.