0% found this document useful (0 votes)
42 views

Python Notes by Rishabh Mishra Chap-07-Input Function

python learning

Uploaded by

Mihirvashishtha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Python Notes by Rishabh Mishra Chap-07-Input Function

python learning

Uploaded by

Mihirvashishtha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PYTHON TUTORIAL FOR BEGINNERS

Source: www.youtube.com/@RishabhMishraOfficial

Chapter - 07

Input Function in Python


• Input Function – Definition
• Input Function – Example
• Handling Different Data Types

Input Function in Python


The input function is an essential feature in Python that allows to take input from
the user. This is particularly useful when you want to create interactive programs
where the user can provide data during execution.
Also known as user input function.
How input Function Works:
The input function waits for the user to type something and then press Enter. It
reads the input as a string and returns it.
Example:
# Prompting the user for their name
name = input("Enter your name: ")
# Displaying the user's input
print("Hello, " + name + "!")

Input Function – Add 2 Numbers


A simple program that takes two numbers as input from the user and prints their
sum.
# Prompting the user for the first and second number
num1 = input("Enter the first number: ")
num2 = input("Enter the second number: ")

P y t h o n N o t e s b y R i s h a b h M i s h ra
# Since input() returns a string, we need to convert it to an integer

num1 = int(num1)
num2 = int(num2)
# Calculating the sum and display the result

sum = num1 + num2


print("The sum of", num1, "and", num2, "is:", sum)

Multiple Input from User & Handling different Data Types


# input from user to add two number and print result
x = input("Enter first number: ")
y = input("Enter second number: ")
# casting input numbers to int, to perform sum
print(f"Sum of {x} & {y} is {int(x) + int(y)}")

Home Work – User input and print result


Write a program to input student name and marks of 3 subjects. Print name and
percentage in output.
# Prompting the user for their name and 3 subject marks

name = input("Enter your name: ")


hindi_marks = input("Enter Hindi Marks: ")
maths_marks = input("Enter Maths Marks: ")
science_marks = input("Enter Science Marks: ")
# Calculating percentage for 3 subjects

percentage = ((int(hindi_marks) + int(maths_marks) +


int(science_marks))/300)*100
# Printing the final results

print(f"{name}, have {percentage}%. Well done & keep


working hard!!")

P y t h o n N o t e s b y R i s h a b h M i s h ra
Python Tutorial Playlist: Click Here
https://www.youtube.com/playlist?list=PLdOKnrf8EcP384Ilxra4UlK9BDJGwawg9

You might also like