for count in range (1, 11):
print count,
print "\nAfter the loop count has the value %d." %count
print "**************"
for count in range(1, 9):
print "* *"
print "**************"
sum = 0
print "Enter the number of integers you want to sum: ",
count = int(raw_input())
for i in range(1, count+1):
sum = sum + i
print "Total of the first %d numbers is %d" %(count, sum)
sum = 0
print "Enter the number of integers you want to sum: ",
count = int(raw_input())
for i in range(1, count+1):
sum = sum + i
print "Total of the first %d numbers is %d" %(count, sum)
sum = 0
print "Enter the number of integers you want to sum: ",
count = int(raw_input())
for i in range(count, 0, -1):
sum = sum + i
print "Total of the first %d numbers is %d" %(count, sum)
print "This program calculates the average of any number of values."
total = 0
count = 0
while True: # infinite loop
print "\nEnter a value: ",
value = float(raw_input())
total += value
count += 1
print "Do you want to enter another value? (Y or N): ",
answer = raw_input()
if(answer.lower() == 'n'):
break
print "The average is %.2f" %(total/count)
import sys
chosen = 15
guess = 0
count = 3
print "This is a guessing game."
print "I have chosen a number between 1 and 20 which you must guess."
for i in range(count, 0, -1):
print "You have %d tr%s left." %(i, ("y" if i == 1 else "ies"));
print "\nEnter a guess: ",
guess = int(raw_input())
if(guess == chosen):
print "Congratulations. You guessed it!"
sys.exit()
elif(guess < 1 or guess > 20):
print "I said the number is between 1 and 20."
else:
print "Sorry, %d is wrong. My number is %s than that.\n" %(guess, ("greater" if chosen > guess else "less"))
print "You have had three tries and failed. The number was %d" % chosen
from random import *
guess = 0
count = 3
limit = 20
chosen = 1 + randint(1, limit) #Random int 1 to limit
print "This is a guessing game."
print "I have chosen a number between 1 and 20 which you must guess."
for i in range(count, 0, -1):
print "You have %d tr%s left." %(i, ("y" if i == 1 else "ies"));
print "Enter a guess: ",
guess = int(raw_input())
if(guess == chosen):
print "Congratulations. You guessed it!"
sys.exit()
elif(guess < 1 or guess > 20):
print "I said the number is between 1 and 20."
else:
print "Sorry, %d is wrong. My number is %s than that.\n" %(guess, ("greater" if chosen > guess else "less"))
print "You have had three tries and failed. The number was %d" % chosen
sum = 0
i = 1
print "Enter the number of integers you want to sum: ",
count = int(raw_input())
while(i <= count):
sum += i
i += 1
print "Total of the first %d numbers is %d" %(count, sum)
MIN_SIZE = 3;
print "Enter values for the width and height (minimum of %d): " % MIN_SIZE
width = int(raw_input("Width: "))
height = int(raw_input("Height: "))
if(width < MIN_SIZE):
print "Width value of %d is too small. Setting it to %d." %(width, MIN_SIZE)
width = MIN_SIZE
if(height < MIN_SIZE):
print "Height value of %d is too small. Setting it to %d." %(height, MIN_SIZE)
height = MIN_SIZE
for i in range(0, width):
print "*",
print "\n"
for j in range(0, height-2):
print "*",
for i in range(0, width-2):
print " ",
print "*"
print "\n"
for i in range(0, width):
print "*",
sum = 0
count = 0
print "Enter the number of integers you want to sum: ",
count = int(raw_input())
for i in range(1, count+1):
sum = 0
for j in range(1, i+1):
sum += j
print "%d\t%5d" %(i, sum)
print "\n"
print "Enter the number of integers you want to sum: ",
count = int(raw_input())
for i in range(1, count+1):
sum = 1
j = 1
print "1",
while(j < i):
j += 1
sum += j
print "+ %d" % j,
print "= %d" % sum
print "\n"
rebmun = 0
print "\nEnter a positive integer: ",
number = int(raw_input())
temp = number
while(temp):
rebmun = 10*rebmun + temp % 10
temp = temp/10
print "The number %d reversed is %d rebmun ehT" %(number, rebmun)