Another beautiful day in this miserable world

Posts tagged ‘python program’

Python Programming: An Introduction to Computer Science by Zelle Chap 3 Ex 11

11. 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():
    print("This program finds the sum of the first 'n' natural numbers")
    print("starting with 0")
    n = eval(input("Enter any natural number "))
    add = 0
    for i in range (n):
        add = add + i
    print(add)
main()

Python Programming: An Introduction to Computer Science by Zelle Chap 3 Ex 10

10. Write a program to determine the length of a ladder required to reach a given height when leaned against a house. Prompt for an angle in degrees and convert it to radians.


from math import *
def main():
    height = eval(input("Please enter the height of the ladder "))
    deg = eval(input("Please enter the angle of the ladder in degrees "))
    rad = (pi/180) * deg
    leng = height/(sin(rad))
    print("The length of the ladder must be ", leng)
main()