Python for Data Science
Test your Python skills with these 20 practice questions and solutions from Day 3 of Learning Python for Data Science. Covers string operations, data types, and more!
x = 10
if x > 5:
print("Greater")
else:
print("Smaller")
Greater
Since x = 10
is greater than 5, the condition if x > 5
is True
, so "Greater"
is printed.
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
num > 0
, it prints "Positive"
.num < 0
, it prints "Negative"
."Zero"
.num = 7
if num % 2 == 0:
print("Even")
else:
print("Odd")
nginxCopyEditOdd
7 % 2
equals 1
, so the condition num % 2 == 0
is False
, and the "Odd"
statement is executed.
x = 15
if x > 10:
if x < 20:
print("Between 10 and 20")
sqlCopyEditBetween 10 and 20
Both conditions x > 10
and x < 20
are True
, so the nested if
block executes.
num = int(input("Enter a number: "))
if num > 0:
if num % 2 == 0:
if num > 10:
print("Positive, Even, and Greater than 10")
x = 5
y = 10
if x > 2:
if y > 5:
print("Valid")
Valid
Since both x > 2
and y > 5
are True
, the print statement executes.
age = int(input("Enter your age: "))
if age <= 12:
print("Child")
elif age <= 19:
print("Teenager")
elif age <= 59:
print("Adult")
else:
print("Senior")
pythonCopyEditx = 50
if x >= 50:
if x == 50:
print("Exactly 50")
else:
print("Greater than 50")
else:
print("Less than 50")
nginxCopyEditExactly 50
Since x == 50
, the "Exactly 50"
statement executes.
pass
statement inside an empty if
condition.x = 10
if x > 5:
pass # Placeholder for future code
else:
print("Smaller")
pass
allows an empty block of code without errors.
pythonCopyEditx = 20
y = 30
if x < y:
if x + 10 == y:
print("Match")
Match
Since x + 10 == y
(20 + 10 = 30), the condition is True
, so "Match"
prints.
num = int(input("Enter a number: "))
if num >= 0:
print("Positive")
else:
print("Negative")
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
x = 10
if x > 5:
print("High")
if x > 8:
print("Higher")
if x > 15:
print("Highest")
High
Higher
Since x = 10
, the first two if
conditions are True
, but the last one is False
.
num = int(input("Enter a number: "))
if num % 2 == 0:
if num % 3 == 0:
print("Divisible by both 2 and 3")
if
statement.num = int(input("Enter a number: "))
if num % 4 == 0:
if num % 6 == 0:
print("Multiple of both 4 and 6")
num = int(input("Enter a number: "))
if num % 2 == 0:
if num > 10:
print("Even and Greater than 10")
num = int(input("Enter a number: "))
if num <= 10:
print("Small")
elif num <= 50:
print("Medium")
else:
print("Large")
x = 3
y = 9
if x < 5:
if y > 8:
print("Success")
Success
num = int(input("Enter a number: "))
if 10 < num < 50:
print("Between 10 and 50")
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")
These practice questions cover Python string manipulation, type conversions, and essential built-in functions. Practicing them will help solidify your understanding of these fundamental concepts.
We hope this article was helpful for you and you learned a lot about data analyst interview from it. If you have friends or family members who would find it helpful, please share it to them or on social media.
Join our social media for more.
Python for Data Science Python for Data Science Python for Data Science Python for Data Science Python for Data Science Python for Data Science Python for Data Science Python for Data Science
Hi, I am Vishal Jaiswal, I have about a decade of experience of working in MNCs like Genpact, Savista, Ingenious. Currently i am working in EXL as a senior quality analyst. Using my writing skills i want to share the experience i have gained and help as many as i can.
Python Practice Questions & Solutions Day 5 of Learning Python for Data Science Welcome back…
Day 5 of Learning Python for Data Science: Data Types, Typecasting, Indexing, and Slicing Understanding…
Python Practice Questions & Solutions Day 4 of Learning Python for Data Science Welcome back…
Day 4 of Learning Python for Data Science Day 4 of Learning Python for Data…
Understanding Python’s conditional statements is essential for controlling the flow of a program. Today, we…
Test your Python skills with these 20 practice questions and solutions from Day 2 of…