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("Enter a number: "))
if (num % 2) == 0:
print("{} is Even".format(num))
else:
print("{} is Odd".format(num))
Thus, the program has been excecuted successfully.
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 has been excecuted successfully.
To write a Python program that prints the characters 'T' and 'a' using character literals.
- Print the character
'T'. - Print the character
'a'.
print('T')
print('a')
Thus, the program has been excecuted successfully.
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.
a = int(input("Enter the real part: "))
b = int(input("Enter the imaginary part: "))
x = complex(a, b)
print("Complex number:", x)
print("Real part:", x.real)
print("Imaginary part:", x.imag)
Thus, the program has been excecuted 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("Enter a string: ")
print(men_stepped_on_the_moon)
Thus, the program has been excecuted successfully.
.png)
.png)
.png)
.png)
.png)