To write a Python program to check whether the given number is even or odd using if...else statements.
- Get an input from the user.
- Convert the input to an integer and store it in a variable
a. - Use the modulo operator
%to check ifa % 2 == 0.- If true, print
"EVEN". - Else, print
"ODD".
- If true, print
- End the program.
num=int(input())
if(num%2==0):
print("Even")
else:
print("Odd")
Thus the program has been successfully executed
To write a Python program that evaluates and prints the results of boolean and arithmetic expressions involving True and False.
- Set variable
ato the result of the expression0 == True. - Set variable
bto the result of the expressionFalse == False. - Set variable
cto the result of the expressionTrue + True. - Set variable
dto the result of the expressionFalse + 9. - Print the value of
awith the label "a is". - Print the value of
bwith the label "b is". - Print the value of
cwith the label "c:". - Print the value of
dwith the label "d:".
a = (0 == True)
b = (False== False)
c = True + True
d = False + 9
print('a is',a)
print('b is',b)
print('c:',c)
print('d:',d)
Thus, the program as been excuted successfully.
To write a Python program that prints the characters 'T' and 'a' using character literals.
- Print the character
'T'. - Print the character
'a'.
v='T'
b='a'
print(v)
print(b)
Thus, the program is executed sucessfully.
To write a Python program that reads two integers, creates a complex number using them, and then prints the complex number along with its real and imaginary parts.
- Read an integer input from the user and assign it to the variable
a(real part). - Read another integer input from the user and assign it to the variable
b(imaginary part). - Create a complex number
xusing thecomplex(a, b)function. - Print the complex number
x. - Print the real part of
xusingx.real. - Print the imaginary part of
xusingx.imag.
x=int(input(''))
y=int(input(''))
x=complex(x,y)
print(x)
print(x.real)
print(x.imag)
Thus, the program as been executed successfully.
To write a Python program to read a string from the user and then print it.
- Assign a variable named
men_stepped_on_the_moon. - Use
input()to read a string from the user and store it in the variable. - Print the value stored in the variable.
men_stepped_on_the_moon=input()
print(men_stepped_on_the_moon)
Thus the program is executed successfully




