0% found this document useful (0 votes)
4 views3 pages

Python Basics: Loops and Conditionals

The document contains Python code snippets demonstrating basic programming concepts such as conditional statements, for loops, and while loops. It includes examples for input handling, summing numbers, checking for even numbers, and evaluating grades based on user input. The code also features user prompts for age and number evaluations, showcasing a variety of control flow structures.

Uploaded by

R V Rockz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Python Basics: Loops and Conditionals

The document contains Python code snippets demonstrating basic programming concepts such as conditional statements, for loops, and while loops. It includes examples for input handling, summing numbers, checking for even numbers, and evaluating grades based on user input. The code also features user prompts for age and number evaluations, showcasing a variety of control flow structures.

Uploaded by

R V Rockz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

x=float(input("Input a number"))

if x==7:
print("Enter a multiple of 2")
else:
print("Good job")

FOR LOOP
for count in range(1,11):
print(count)

sum = 0
for count in range(1,6):
sum=sum + count
print("The sum is: ",sum)

for count in range(1,11):


if count %2 == 0:
print(count)

for count in range(1,31):


if count %3 == 0:
print(count)

sum = 0
for count in range(1,6):
marks = float(input("Enter marks: "))
sum = sum + marks
print("The sum is", sum)

num = float(input("Enter a number"))


for count in range(1,11):
print(num,"x", count,("="), num*count)

pos = 0
for count in range(1,6):
num = int(input("Enter a number"))
if num > 0:
pos = pos + 1
print(pos)
WHILE LOOP

count = 0
while count < 5:
print("*")
count = count + 1

count = 1
while count <11:
count = count + 1
if count %2==0:
print(count)

count = 0
while count < 10:
count = count + 1
if count %2 == 0:
print("even")
else:
print(count)

count = 1
while count < 11:
print("3 x", count,("="), count*3)
count = count + 1

CONDITIONAL STATEMENT

age = float(input("Enter age: "))


if age>=18:
print("you are an adult")
elif age>100:
print("you are dead")
else:
print("you are a child")

Grade = input("Enter Grade: ")


if Grade == 'A' or Grade == 'a':
print("very good")
elif Grade == 'B' or Grade == 'b':
print("good")
elif Grade == 'C' or Grade == 'c':
print("work harder")
elif Grade == 'D' or Grade == 'd':
print("need improvement")

num = float(input("Enter a number"))


if num>0:
print("The number is positive")
else:
print("The number is negative")
if num == 0:
print("Number is 0")

You might also like