TOPIC: Python Input Operation, Expressions in Python & Type Conversion
Input Operation
Using the input() function: The input() function is used to receive user input as a string. By
default, the data-type for the input() function is a string data-type. Let us look at an example
where the user is prompted to enter something and the input is stored as a string in the variable -
user_input.
Example
user_input = input("Enter something: ")
It is used to prompt the users and instruct them on what to enter. The prompt inside the input() function is displayed to the user, indicating what kind of input is expected. We also need to handle the user input appropriately to ensure that our program behaves correctly. We can add conditions to check the user input and prevent errors.
Expressions in Python
Type Conversion:
Code as discussed in the video:
# Python Input Operations
# inputVar = input("Enter your name: ") # string by default
# print("My name is ", inputVar)
# inputVarI = int(input("Enter your age: "))
# print("My age is ", inputVarI)
# floatVar = float(input("Enter any floating number: "))
# print(floatVar)
# Python Expressions
# 1. Infix # 2. Prefix # 3. Postfix
# num1 = 5
# num2 = 4
# infix
# num3 = num1 - num2 # the operator is between the operands
# print(num3)
# prefix
# num4 = *num1 num2 # the operator is before the operands
# postfix
# num5 = num1 num2* # the operator is after the operands
# Type Conversion
# num1 = float(input("Enter a number: "))
# num2 = float(input("Enter another number: "))
# num3 = num1+num2
# print(int(num3))
'''
Q.1 Write a python program to calculate the area of an rectangle and also its perimeter
- accept values from the user
- use float type for the length and the breadth
- store the value in area, peri and print it
Q.2 Write a python program to calculate the area of a circle and also its circumference
- pi = 3.14
- accept values from the user
- use float type for the radius
- store the value in carea, circum
'''
You can copy and run this code