Tuesday, October 24, 2017

Python If, slif and else

#Simple if

def main():
    number = int(input("Enter a number "))
    if number > 5:
        print ("the number is bigger than 5")
    elif number==5:
        print ("the number is 5")
    else:
        print("The number is less than 5")

main()

Here is the grading decision tree

#Grade scores between 100 and 0
#broken into 4 point system

def getScore():
    score=int(input("enter the test score "))
    return score

def getGrade(score):
    grade = 0.0
    if score >= 90:
        grade = 4.0
    elif score >= 85:
        grade = 3.5
    elif score >= 80:
        grade=3.0
    elif score >= 75:
        grade = 2.5
    elif score >= 70:
        grade = 2.0
    elif score >= 65:
        grade = 1.0
    else:
        grade= 0.0
    return grade

def printGrade(grade):
    print ("Your test grade is ", grade)

def main():
    testScore = getScore()
    #print(testScore)
    gradePoint = getGrade(testScore)
    printGrade(gradePoint)


main()

   
    

The prime number program

#Code will generate 41 prime number

def getNumber():
    number = int(input("Enter a number between 0 to 40: "))
    return number

def checkNumber(number):
    checkedNumber=0
    if number >=0 and number <=40:
        checkedNumber = number
    else:
        checkedNumber=-1
    return checkedNumber
    
        
def getPrime(number):
    prime = number * number - number +41
    return prime

def printPrime(prime):
    print ("The prime number is", prime)

def main():
    num = getNumber()
    checkNum = checkNumber(num)
    #print(checkNum)
    if checkNum == -1:
        print ("Numbers must be between 0 and 40")
        return
    prime = getPrime(num)
    printPrime(prime)

main()




        

Wages

#peer execise 6
#Wages with overtime

def getWage():
    rate = float(input("Enter your hourly rate"))
    return rate

def getHours():
    hours = float(input("Enter your weekly hours"))
    return hours

def calculateGross(rate, hours):
    gross=0
    overtimeRate=1.5
    regHours=40
    if hours > regHours:
        gross=rate * (regHours + ((hours-regHours)*overtimeRate))
    else:
        gross=rate * hours
    return gross

def printGross(gross):
    print("Your gross pay is",gross)

def main():
    rate = getWage()
    hours = getHours()
    gross=calculateGross(rate, hours)
    printGross(gross)


main()
    
    

No comments:

Post a Comment