Im trying to write a program to add a bonus every time u input 3 consecutive fractions that equal 1. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Im trying to write a program to add a bonus every time u input 3 consecutive fractions that equal 1.

basically the input are grades that are a fraction points available/points gotten. i want it to b that if you get all available points for three straight attempts there is a bonus of 1/5.

2nd Dec 2016, 4:34 PM
david
3 Answers
+ 1
update : you don't need "and" operator I thought you meant each fraction equals 1 .
3rd Dec 2016, 10:36 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
is there a way to write it so i dont have to write each possibility. for example if i were to continue that way it would look like: elif second_try ==1 and third_try ==1 and fourth_try ==1: bonus += yourbonus this would get kind of tiresome. i was wondering if there is a way to get the input into a list and then check every three consecutive ps im kinda new to this so i dont know if i make any sense thanx!
2nd Dec 2016, 8:37 PM
david
0
i'm not sure I fully understand your goal . that's not something a beginner would do . it's not tiresome. here is how it would be if a beginner did it : code : bonus = 0 counter = 0 while counter < 3: if counter == 0 : first_number = float(input("Enter the first fraction :")) counter += 1 # increment counter by 1 elif counter== 1: second_number= float(input("Enter the second fraction :")) counter += 1 else: third_number = float(input("Enter the third fraction :")) counter += 1 # we collected the three fractions . # check if they equal 1 if first_number+ second_number + third_number == 1: bonus += bonusvalue # add a bonus else: print(" you didn't get the bonus")
3rd Dec 2016, 10:30 AM
Bahhaⵣ
Bahhaⵣ - avatar