Python structure
Points to remember:
Always write data type for numbers for eg int or float before input, because python
use str data type by default.
Syntax of input for int or float data type is : int( input(“ your prompt here “))
Syntax of input for str data type is : input(“ your prompt here “)
Example question:
A student appears in three subjects. The school wants a program that:
Takes marks of three subjects English, Urdu and Maths
Calculates the total and average
Displays Pass if average is 50 or above, otherwise Fail
Python Solution:
Variable Data type Input statement
englishmarks = int(input("Enter marks of English: ")) Prompt
urdumarks = int(input("Enter marks of Urdu: "))
mathsmarks = int(input("Enter marks of Maths: "))
total = englishmarks + urdumarks + mathsmarks
average = total / 3
print("Total:", total)
print("Average:", average)
if average >= 50:
print("Result: Pass")
else:
print("Result: Fail")