Basic if else loop coding questions in python
here are some basic if/else loop coding interview questions in Python:
- Write a Python program that takes a number as input from the user and prints “Even” if the number is even and “Odd” if the number is odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")2. Write a Python program that takes two numbers as input from the user and prints the larger of the two numbers.
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if num1 > num2:
print(num1, "is larger")
else:
print(num2, "is larger")3. Write a Python program that takes a list of numbers as input from the user and prints the sum of all the even numbers in the list.
num_list = input("Enter a list of numbers separated by space: ").split()
sum = 0
for num in num_list:
if int(num) % 2 == 0:
sum += int(num)
print("Sum of even numbers:", sum)These are just a few examples of basic if/else loop coding interview questions in Python. There are many more possible questions that can be asked depending on the level of the interview.
Get Data Sequel’s stories in your inbox
Join Medium for free to get updates from this writer.
here are some more if/else loop coding questions in Python:
4. Write a Python program that takes a string as input from the user and prints whether the string is a palindrome or not.
string = input("Enter a string: ")
if string == string[::-1]:
print("The string is a palindrome")
else:
print("The string is not a palindrome")5. Write a Python program that takes a list of numbers as input from the user and prints the largest number in the list that is divisible by 3.
num_list = input("Enter a list of numbers separated by space: ").split()
max_num = -1
for num in num_list:
if int(num) % 3 == 0 and int(num) > max_num:
max_num = int(num)
if max_num == -1:
print("There is no number in the list that is divisible by 3")
else:
print("The largest number in the list that is divisible by 3 is", max_num)6. Write a Python program that takes a list of integers as input from the user and returns a new list with all the duplicate values removed.
num_list = input("Enter a list of numbers separated by space: ").split()
new_list = []
for num in num_list:
if num not in new_list:
new_list.append(num)
print("Original list:", num_list)
print("List with duplicates removed:", new_list)please subscribe to https://datasequelnet.com/ebooks for more ebooks related to coding and data science articles.








