number=12 #number=int(raw_input("Type in your number: "))
try:
if( number < 0 ):
number=-number #change sign,if number is negative
except:
print "not a number" #Invalid input/value error
print ("The absolute Value is {0}".format(number))
gradeTotal=0
failureCount=0
i=0
numberOfGrades=5 #numberOfGrades=int(raw_input("How many grades will you be entering? "))
grade=[72,83,91,89,95]
while(i<numberOfGrades):
gradeTotal=gradeTotal+grade[i]
if(grade<65):
failureCount=failureCount+1;
i=i+1
average=float(gradeTotal/numberOfGrades)
print("Grade average= {0:.2f}".format(average))
print("Number of failures= {0}".format(failureCount))
number_to_test=30 #number_to_test=int(raw_input("Enter your number to be tested: "))
remainder=number_to_test%2
if(remainder==0):
print("The number is even")
if(remainder!=0):
print("The number is odd")
number_to_test=45 #number_to_test=int(raw_input("Enter your Number to be tested: "))
remainder=number_to_test%2
if(remainder==0):
print("The number is even.\n")
else: #using 'else' instead of second 'if'
print("The number is odd.\n")
year=1900 #year=int(raw_input("Enter the year to be tested: "))
rem_4=year%4
rem_100=year%100
rem_400=year%400
if((rem_4==0 and rem_100!=0)or rem_400==0):
print("It's a leap year.")
else:
print("Nope, it's not a leap year.\n")
number=450 #number=int(raw_input("Please type in a number: "))
try:
if(number<0): #Negative Number
sign=-1
elif(number==0): #No sign
sign=0
else: #Positive Number
sign=1
except: #Value error
print("invalid input")
print("Sign= {0}".format(sign))
ch='z' #ch=raw_input("Enter a single character: ")
if((ch>='a' and ch <='z') or (ch>='A' and ch<='Z')):
print("It's an alphabetic character.")
elif(ch>='0'and ch<='9'):
print("It's a digit.")
else:
print("It's a special character")
try:
print("Type in your expression(with spaces inbetween): ")
value1, operator, value2="5 + 2".split()
#value1, operator, value2=raw_input().split()
except:
print("err.. follow the syntax <value operator value>")
print("with spaces inbetween\n")
value1,value2=[float(value1),float(value2)]
if(operator=='+'):
print("answer: {0:.2f}".format(value1+value2))
elif(operator=='-'):
print("answer: {0:.2f}".format(value1-value2))
elif(operator=='*'):
print("answer: {0:.2f}".format(value1*value2))
else:
print("answer: {0:.2f}".format(value1/value2))
try:
print("Type in your expression(with spaces inbetween): ")
value1, operator, value2="3 * 5".split()
#value1, operator, value2=raw_input().split()
except:
print("err.. follow the syntax <value operator value>")
print("with spaces inbetween\n")
value1,value2=[float(value1), float(value2)]
if(operator=='+'):
print("Answer= {0:.2f}".format(value1+value2))
elif(operator=='-'):
print("Answer= {0:.2f}".format(value1-value2))
elif(operator=='*'):
print("Answer= {0:.2f}".format(value1*value2))
elif(operator=='/'):
if(value2==0):
print("Whoops! divide by 0 issue")
else:
print("Answer= {0:.2f}".format(value1/value2))
else:
print("err.. Invalid operator")
p=2
while(p<=50): #Outer loop
isPrime=1 #Variable declaration
d=2
while(d<p): #Inner loop
if(p%d==0):
isPrime=0
d=d+1 #End of inner loop
if( isPrime!=0):
print " ",p
p=p+1 #End of outer loop