number = 0;
print "\nEnter an integer between 1 and 10: ",
number = int(raw_input())
if(number > 5):
print "You entered %d which is greater than 5\n" % number
if(number < 6):
print "You entered %d which is less than 6\n" % number
unit_price = 3.50
print "Enter the number that you want to buy: ",
quantity = int(raw_input())
if(quantity > 10):
total = quantity*unit_price*0.95 # 5% discount
print "The price for %d is $%.2f\n" % (quantity, total)
else:
total = quantity*unit_price #no discount
print "The price for %d is $%.2f\n" % (quantity, total)
test = 0.0
print "Enter an integer: ",
test = int(raw_input())
if(test % 2 == 0):
print "The number %ld is even" %test
if((test/2) % 2 == 0):
print "Half of %d is also even" %test
print "That's interesting isn't it?"
else:
print "The number %d is odd\n" %test
print "Enter an uppercase letter:",
letter = raw_input()
if(ord(letter) >= ord('A')):
if(ord(letter) <= ord('Z')):
letter = chr( ord(letter) - ord('A') + ord('a'))
print "You entered an uppercase %c" %letter
else:
print "Try using the shift key! I want a capital letter.\n"
print "Enter an uppercase letter:",
letter = raw_input()
if( (ord(letter) >= ord('A')) and (ord(letter) <= ord('Z')) ):
letter = chr( ord(letter) - ord('A') + ord('a'))
print "You entered an uppercase %c" %letter
else:
print "You did not enter an uppercase letter."
unit_price = 3.50
discount1 = 0.05
discount2 = 0.1
discount3 = 0.15
total_price = 0.0
print "Enter the number that you want to buy:",
quantity = int(raw_input())
if(quantity >50):
total_price = quantity*unit_price*(1.0-discount3)
elif(quantity > 20):
total_price = quantity*unit_price*(1.0-discount2)
elif(quantity > 10):
total_price = quantity*unit_price*(1.0-discount1)
else:
total_price = quantity*unit_price*(1.0-0.0)
print "The price for %d is $%.2f\n" %(quantity, total_price)
age = 0
college = 0
subject = 0
interview = False # true for accept, false for reject
print "What college? 1 for Harvard, 2 for Yale, 3 for other: ",
college = int(raw_input())
print "What subject? 1 for Chemistry, 2 for economics, 3 for other: ",
subject = int(raw_input())
print "How old is the applicant? ",
age = int(raw_input())
if( (age>25 and subject==1) and (college==3 or college == 1) ):
interview = True
if(college == 2 and subject == 1):
interview = True
if(college == 1 and subject == 2 and not(age > 28)):
interview = True
if(college == 2 and (subject == 2 or subject == 3) and age > 25):
interview = True
if(interview):
print "Give 'em an interview"
else:
print "Reject 'em"
print "Pick a number between 1 and 10 and you may win a prize! ",
choice = int(raw_input())
if((choice > 10) or (choice < 1)):
choice = 11
if choice == 7:
print "Congratulations!"
print "You win the collected works of Amos Gruntfuttock."
elif choice == 2:
print "You win the folding thermometer-pen-watch-umbrella."
elif choice == 8:
print "You win the lifetime supply of aspirin tablets."
elif choice == 11:
print "Try between 1 and 10. You wasted your guess.",
else:
print "Sorry, you lose.\n"
print "Enter Y or N: ",
answer = raw_input()
if answer =='y' or answer == 'Y':
print "You responded in the affirmative."
elif answer == 'n' or answer == 'N':
print "You responded in the negative."
else:
print "You did not respond correctly. . ."
original = 0xABC
result = 0
mask = 0xF
print "original = %X" % original
result |= original & mask
original = original >> 4
result = result << 4
result |= original&mask
original = original >> 4
result = result << 4
result |= original & mask
print "result = %X" % result
print "Enter the calculation\n",
number1 = float(raw_input("Enter first number: "))
number2 = float(raw_input("Enter second number: "))
operation = raw_input("Enter operation '+' or '-' or '/' or '%' or '*': ")
if operation == '+':
print "= %f" %(number1 + number2)
elif operation == '-':
print "= %f" %(number1 - number2)
elif operation == '*':
print "= %f" %(number1 * number2);
elif operation == '/':
if(number2 == 0):
print "Division by zero error!"
else:
print "= %f\n" %(number1 / number2)
elif operation == '%':
if(number2 == 0):
print "Division by zero error!"
else:
print "= %f\n" %(number1 % number2)
else:
print "Illegal operation!"