CODE
def main() :
print ("This program computes the area of Rectangle")
length = float (input ("Enter length: ") )
width = float (input ("Enter width: ") )
ans = length * width
print ("Area of Rectangle: ", ans)
main()
getsprogramming Tutorials , C Programming, CPP Programming and JAVA Programming , Python Programming , Javascript Programming Welcome to getsprogramming Blog Here You Find Different Programs in Easier way to Explain and gain Knowledge and Try Your Self..Thanks
CODE
def main() :
print ("This program computes the area of Rectangle")
length = float (input ("Enter length: ") )
width = float (input ("Enter width: ") )
ans = length * width
print ("Area of Rectangle: ", ans)
main()
CODE
def main() :
print ("This program computes the area of Cylinder")
rd = float (input ("Enter Radius of Cylinder: ") )
h = float (input ("Enter Height of Cylinder: ") )
ans = 2 * 3.14 * rd * h + 2 * 3.14 * rd *rd
print ("Area of Cyclinder: ", ans)
main()
save file as areaofcylinder.py
SCREENSHOT
CODE
def main() :
print ("This program computes the area of circle")
rd = float (input ("Enter Radius of Circle: ") )
ans = 3.14 * rd *rd
print ("Area of Circle: ", ans)
main()
CODE :
An archery target consists of a central circle of yellow surrounded by concentric rings of red, blue, black and white. Each ring has the same width, which is the same as the radius of the yellow circle. Write a program called target.py that draws this target.
o Use a list of colors and a for loop to draw the target
o Hint: objects drawn later will appear on top of objects drawn earlier
o The output of the program should look like this:
SCREENSHOT
SAVE this file as target.py
from graphics import *
def main():
win = GraphWin('Archery Target',300,300)
center = Point(150,150)
w = Circle(center, 100)
w.setFill('white')
w.draw(win)
bl = Circle(center, 80)
bl.setFill('black')
bl.draw(win)
b = Circle(center, 60)
b.setFill('blue')
b.draw(win)
r = Circle(center, 40)
r.setFill('red')
r.draw(win)
y = Circle(center, 20)
y.setFill('yellow')
y.draw(win)
win.getMouse() # pause for click in window
win.close()
main()
Write a program that finds the average of a series of numbers entered by the user. As in the previous problem, the program will first ask the user how many numbers there are. Note: The average should always be a float, even if the user inputs are all ints.
CODE :
# sumnn.py
def main() :
n = int (input ("How many numbers are to be summed: ") )
sum=0
for i in range(n) :
a = int (input ("Please enter number : ") )
sum=sum+a
print ("Average of a series of numbers :",sum/n)
main()
SCREENSHOT
Write a program to sum a series of numbers entered by the user. The program should first prompt the user for how many numbers are to be summed. The program should then prompt the user for each of the numbers in turn and print out a total sum after all the numbers have been entered. Hint: Use an input statement in the body of the loop.
CODE
# sumnn.py
def main() :
n = int (input ("How many numbers are to be summed: ") )
sum=0
for i in range(n) :
n = int (input ("Please enter number : ") )
sum=sum+n
print ("Total Sum :",sum)
main()
SCREENSHOT
CODE
# tablen.py
def main() :
n = int (input ("Please enter number: ") )
for i in range(1,11) :
sum=n*i
print (n,"*",i,"=",sum)
main()
Note :save above file as : tablen.py
SCREENSHOT
CODE :
# sumn.py
# Write a program to find the sum of the first n natural numbers,
#where the value of n is provided by the user.
def main() :
sum=0
n = int (input ("Please enter number: ") )
for i in range(n+1) :
sum=sum+i
print ("Sum of n Natural number is :",sum)
main()
CODE
# factorial. py
# Program to compute the factorial of a number
# Illustrates for loop with an accumulator
def main() :
n = int (input ("Please enter a whole number: ") )
fact = 1
for factor in range(n,1,-1) :
fact = fact * factor
print ("The factorial of", n, "is", fact)
main ()
NOTE : save above program as factorial.py
SCREENSHOT
CODE
#kmtomiles.py
#Python program :It coverts kilometer to miles
def main():
print("This program convert Kilometers to miles")
km=eval(input("Enter Kilometers ?"))
miles = 0.62 * km
print("Aha , I know Miles are ",miles)
main()
NOTE : save above file as kmtomiles.py
SCREENSHOT
CODE
def main() :
print ("This program computes the average of two exam scores. ")
score1, score2,score3 = eval (input ("Enter three scores separated by a comma: ") )
average = (score1 + score2 + score3) / 3
print ("The average of the scores is: ", average)
main()
SCREENSHOT
CODE
def main() :
print ("This program computes the average of two exam scores. ")
score1, score2 = eval (input ("Enter two scores separated by a comma: ") )
average = (score1 + score2) / 2
print ("The average of the scores is: ", average)
main()
SCREENSHOT
CODE :We want to develop a program to determine the future value of an investment.
def main () :
print ("This program calculates the future value")
print ("of a 10-year investment.")
principal = eval (input ("Enter the initial principal: $") )
apr = eval (input ("Enter the annual interest rate: ") )
for i in range (10) :
principal = principal * (1 + apr)
print ("The value in 10 years is: $", principal)
main ()
save above program as futval.py
SCREENSHOT
def main():
x=10
y=20
sum = x + y
print("X's Value=",x)
print("Y's Value=",y)
print("Summation of X + Y =",sum)
main()
Note : Save above code as prog2.py