Computer Science - Python Codes..
Computer Science - Python Codes..
#1. write a python code to add two numbers and print the total
#2. write a python code to compare two numbers and print the largest
#3. write a python code to compare three numbers and print the largest (this was
given as a H.W)
#while loop
total=0
count=0
while count<21:
total=total+count
count=count+1
print("The total is", total)
#for loop
total=0
for count in range(0,21):
total=total+count
print("The total is", total)
#5. write a python code to find the sum of all even numbers between 0-10 and print
the total
#while loop
total=0
count=0
while count<11:
total=total+count
count=count+2
print("The total is", total)
#for loop
total=0
for count in range(0,11,2):
total=total+count
print("The total is", total)
#6. write a python code to find the sum of all odd numbers between 0-10 and print
the total
#while loop
total=0
count=1
while count<11:
total=total+count
count=count+2
print("The total is", total)
#for loop
total=0
for count in range(1,11,2):
total=total+count
print("The total is", total)
#7. write a python code for the guessing game (practice paper 1) (this was given as
a H.W)
number=20
guess=0
while guess!=20: #the != is for not equal
guess=int(input("Not matching, please guess again!"))
print("they match and you won!")