Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function problem
#5
Here your code now with function call.
And i call with a smaller number,try this 1980 ** 1980 get really big.
def birthexp(birthyear):
    product = birthyear**birthyear
    length = len(str(product))
    onesCount = str(product).count("1")
    threeCount = str(product).count("3")
    fiveCount = str(product).count("5")
    sevenCount = str(product).count("7")
    nineCount = str(product).count("9")
    sumCount = onesCount+threeCount+fiveCount+sevenCount+nineCount
    oneRation = onesCount/float(length)*100
    threeRatio = threeCount/float(length)*100
    fiveRatio = fiveCount/float(length)*100
    sevenRatio = sevenCount/float(length)*100
    nineRatio = nineCount/float(length)*100
    totalRatio = sumCount/float(length)*100
    print(str(product) + ": product after multiplying the birth year to itself.")
    print(str(onesCount) + ": number of ones found at a rate of " +str(oneRation)+ "percent.")
    print(str(threeCount) + ": number of threes found at a rate of " +str(threeRatio)+ "percent")
    print(str(fiveCount) + ": number of fives found at a rate of " +str(fiveRatio)+ "percent")
    print(str(sevenCount) + ": number of sevens found at a rate of " +str(sevenRatio)+ "percent")
    print(str(nineCount) + ": number of nine found at a rate of " +str(nineRatio)+ "percent")
    print(str(sumCount) + ": total odd numbers found at a rate of " +str(totalRatio)+ "percent")

birthexp(2)
Output:
4: product after multiplying the birth year to itself. 0: number of ones found at a rate of 0.0percent. 0: number of threes found at a rate of 0.0percent 0: number of fives found at a rate of 0.0percent 0: number of sevens found at a rate of 0.0percent 0: number of nine found at a rate of 0.0percent 0: total odd numbers found at a rate of 0.0percent
Reply


Messages In This Thread
Function problem - by garretmorion - Jan-14-2017, 05:17 PM
RE: Function problem - by buran - Jan-14-2017, 05:23 PM
RE: Function problem - by snippsat - Jan-14-2017, 05:24 PM
RE: Function problem - by garretmorion - Jan-14-2017, 05:25 PM
RE: Function problem - by snippsat - Jan-14-2017, 05:35 PM
RE: Function problem - by garretmorion - Jan-14-2017, 05:37 PM
RE: Function problem - by wavic - Jan-14-2017, 05:39 PM
RE: Function problem - by garretmorion - Jan-14-2017, 05:42 PM
RE: Function problem - by buran - Jan-14-2017, 05:42 PM
RE: Function problem - by snippsat - Jan-14-2017, 05:50 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020