You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Get input from useryear=raw_input('Enter year: ')
year=int(year)
# Calculate leap yearif ((year%4==0) and (year%100!=0)) or (year%400==0):
print"Yes"else:
print'No'
Exercise 2 : Grading System
grade=raw_input('Enter grade: ')
grade=float(grade)
ifgrade>90:
print'A'elif (grade>=80) and (grade<=90):
print'B'elif (grade>=70) and (grade<=79):
print'C'elif (grade>=60) and (grade<=69):
print'D'else:
print'E'
Exercise 3 : Calculator
# Get user inputprint"Choose from the ff operation: "print"add,subtract,multiply,divide"operation=raw_input('enter: ')
# Perform operationsifoperation=='add':
x=raw_input('Enter first number : ')
y=raw_input('Enter second number: ')
printfloat(x) +float(y)
elifoperation=='subtract':
x=raw_input('Enter first number : ')
y=raw_input('Enter second number: ')
printfloat(x) -float(y)
elifoperation=='divide':
x=raw_input('Enter first number : ')
y=raw_input('Enter second number: ')
printfloat(x) /float(y)
elifoperation=='multiply':
x=raw_input('Enter first number : ')
y=raw_input('Enter second number : ')
printfloat(x) *float(y)
else:
print'operation not found :('
Exercise 4 : Factorial
# Get user inputx=int(raw_input('Enter number: '))
accumulator=1foriinrange(1,x+1):
accumulator=accumulator*iprint"Factorial of "+str(x) +" is = "+str(accumulator)
Exercise 5: Fibonacci
# Get user inputinput=int(raw_input('Enter number: '))
# set variablesx=1y=1temp=x# since 0 is not included in the sequence, print 0ifinput==0:
print"zero is not included in the sequence"exit()
# calculate the fibonacci numberforiinrange(input-1):
x=yy=temp+ytemp=xprint"Fibonacci of "+str(input) +" is "+str(x)
Exercise 6 : Find the even numbers on a list
# Hardcoded listnumber_list= [2,5,7,8,9,10,11,12,13,15,16,17,18]
final_list= []
# variable holdertemp=0# process the listfornumberinnumber_list:
ifnumber%2==0:
temp=number+1else:
temp=numberfinal_list.append(temp)
temp=0printfinal_list
Exercise 7 : Philippine Peso to USD conversion rates na hindi naman pala >__>
# hardcoded datadata= [41,42,43,44,45,45,47,48,49,50]
# important(?) variables hahahaui_string="Choices: average,add,max,min,count,distinct,exit \n"input=""# process user inputwhileinput!='exit':
input=raw_input(ui_string)
ifinput=='average':
printsum(data)/len(data)
elifinput=='add':
number=float(raw_input('Enter number to add: '))
data.append(number)
print'number added'elifinput=='max':
printmax(data)
elifinput=='min':
printmin(data)
elifinput=='length':
printlen(data)
elifinput=='count':
number=float(raw_input('Enter a new value: '))
printstr(number) +" has "+str(data.count(number)) +" instance(s)"elifinput=='distinct':
printlist(set(data))