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

If Else: Enter Num15 Enter Num23 3 Num2 Is Smaller

This document contains Python code snippets for solving various problems related to numbers, loops, lists, and conditionals. The code examples demonstrate how to check if a number is even or odd, find the largest or smallest number, iterate through loops to print patterns, count even and odd numbers in a list, calculate simple interest, and check if a year is a leap year. The document serves as a collection of Python homework examples for learning basic programming concepts.

Uploaded by

priyanjay
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)
37 views3 pages

If Else: Enter Num15 Enter Num23 3 Num2 Is Smaller

This document contains Python code snippets for solving various problems related to numbers, loops, lists, and conditionals. The code examples demonstrate how to check if a number is even or odd, find the largest or smallest number, iterate through loops to print patterns, count even and odd numbers in a list, calculate simple interest, and check if a year is a leap year. The document serves as a collection of Python homework examples for learning basic programming concepts.

Uploaded by

priyanjay
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
You are on page 1/ 3

4/14/2020 Homework

In [1]: num1= int(input("Enter num1"))


num2= int(input("Enter num2"))
if num1<num2:
print(num1," num1 is smaller")
else:
print(num2," num2 is smaller")

Enter num15
Enter num23
3 num2 is smaller

In [2]: num1= int(input("Enter num1"))


num2= int(input("Enter num2"))
num3= int(input("Enter num3"))
if num1<num2 and num1<num3:
print(num1,"num1 is smallest")
elif num2<num3:
print(num2,"num2 is smallest")
else:
print(num3, "num3 is smallest")

Enter num15
Enter num22
Enter num31
1 num3 is smallest

In [4]: num= int(input("Enter num"))


if num%2==0:
print(num," is even")
else:
print(num," is odd")

Enter num5
5 is odd

In [9]: num= int(input("Enter num"))


if num>=1 and num<=100:
print(num," is between 1 and 100")
else:
print(num,"is not between 1 and 100")

Enter num101
101 is not between 1 and 100

In [11]: num=5
for x in range(1,num+1):
print("*****")

*****
*****
*****
*****
*****

file:///C:/Users/DANI-ANNE/Downloads/Homework.html 1/3
4/14/2020 Homework

In [2]: num=5
for x in range(1,num+1):
for y in range(1,num+1):
print(x,end='')
print()

11111
22222
33333
44444
55555

In [17]: num=5
for x in range(1,num+1):
for y in range(1,num+1):
print(y,end='')
print()

12345
12345
12345
12345
12345

In [21]: letters= ["A","B","C","D","E"]


num=5
for x in letters:
print(x*num)

AAAAA
BBBBB
CCCCC
DDDDD
EEEEE

In [ ]: list= eval(input("Enter a list"))


odd,even=0,0
for x in list:
if x%2==0:
even+=1
else:
odd+=1
print(odd," odds ",even,"evens")

In [ ]: init= input("Enter intitial amount")


inter= input("enter interest percent")
years=input("enter how many years")
print(init*inter*years/100," equals your interest")

Enter intitial amount5

file:///C:/Users/DANI-ANNE/Downloads/Homework.html 2/3
4/14/2020 Homework

In [ ]: x= input("Enter value of x")


y= input("Enter value of y")
x=z
x=y
y=z
print("x equals ",x)
print("y equals ",y)

In [ ]: year= input("Enter year")


if year%100==0:
if year%400==0:
print("leap year")
else:
print("not a leap year")
elif year%4==0:
print("leap year")
else:
print("not a leap year")

In [ ]: num=input("enter number")
for x in range(2,10):
if num%x==0:
print("not prime")
print("prime")

In [ ]: answer=="y"
list=[]
while answer=="y":
num=input("Enter num")
index=0
for x in num:
list[index]=x
answer=input("more numbers y or n")
print(list)

In [ ]:

file:///C:/Users/DANI-ANNE/Downloads/Homework.html 3/3

You might also like