+ 1

Software logic problem

bag1 = int(input('Bag 1 weight is: ')) bag2 = int(input('Bag 2 weight is: ')) if bag1+bag2 <= 46: print('good') if bag1+bag2 > 46: print('You have too much packed.') elif bag1 >= 23: print('Bag 1 is too heavy.') elif bag2 >= 23: print('Bag 2 is too heavy.') This is a code that i have been working On and runs perfectly but the probelm arises. Let me explain. These are the three rules: Each bag has to be under or equal to 23 and if any bag is higher then 23, display the heavy bag eg- bag 1 is heavy Total weight should be 46 or lower and if higher then 46 then it should display “you have packed too much” If total weight is 46 and all bag are 23, then show “good” Now the only logic I am having trouble is the 3rd rule. Also, in future if i ever encounter this problem... then how do I approach + any tips of shortening the code and making it efficient?

29th Jul 2019, 7:13 AM
Dingo
Dingo - avatar
7 Antworten
+ 2
if bag1 + bag2 <= 46: if bag1 > 23: print("Bag1 too heavy") elif bag2 > 23: print("Bag2 too heavy") else: print("All good 👍🏼") else: print("too heavy")
29th Jul 2019, 7:19 AM
Trigger
Trigger - avatar
+ 1
This is just a basic implementation to show the logic
29th Jul 2019, 7:20 AM
Trigger
Trigger - avatar
+ 1
If bag1 <= 23 and bag2 <= 23: If bag1 + bag2 <= 46: Print('good') Else: Print('too heavy')
29th Jul 2019, 7:23 AM
Mauricio De Martino
Mauricio De Martino - avatar
+ 1
~ swim ~ NIICE
29th Jul 2019, 9:16 AM
Trigger
Trigger - avatar
0
This is just somthing that i am curious to see if anyone else have shorter or better solutions then mine. sorry about the basic stuff..
29th Jul 2019, 7:14 AM
Dingo
Dingo - avatar