0% found this document useful (0 votes)
12 views2 pages

Python Class

The document provides examples of taking different types of inputs in Python, including integers, floats, and strings. It demonstrates how to format strings using the .format() method with both indexed and named placeholders. Additionally, it includes a simple program to calculate and print the sum of two numbers using f-strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Python Class

The document provides examples of taking different types of inputs in Python, including integers, floats, and strings. It demonstrates how to format strings using the .format() method with both indexed and named placeholders. Additionally, it includes a simple program to calculate and print the sum of two numbers using f-strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Integer Input

age = int(input("Enter your age: "))

print("You are", age, "years old.")

Float Input

price = float(input("Enter the price: "))

print("The price is:", price

Basic Input (String)

name = input("Enter your name: ")

print("Hello, " + name + "!")

Format()

name = "Alice"

age = 25

print("My name is {} and I am {} years old.".format(name, age))

Output:

My name is Alice and I am 25 years old.

Using Indexed .format()

name = "Alice"

age = 25

print("My name is {0} and I am {1} years old.".format(name, age))

Output:

My name is Alice and I am 25 years old.


Using Named Placeholders in .format()

name = "Alice"

age = 25

print("My name is {n} and I am {a} years old.".format(n=name, a=age))

Output

My name is Alice and I am 25 years old.

sum of two numbers

# Taking two numbers as input

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

# Calculating sum

sum_result = num1 + num2

# Printing the result using f-string

print(f"The sum of {num1} and {num2} is {sum_result}")

You might also like