Python Forum
help me make this code better please (basic)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help me make this code better please (basic)
#4
Hi, you have hier two cycles on the same values:

i=1
my_list = []
while i <=10:
    try: 
        my_list.append(int(input('please enter your discussions scores: '))) 
        i += 1
     
    except: 
        print('you made an error,please try again')
print(my_list)
 
 
l=[]
for x in my_list: 
    dis_score = x * (2/100)
    l.append(dis_score)
 
print('your total percentage from discussion scores is: '+ str(sum(l)))
they can be combined into one:

my_list = []
l = []
for i in range(10):
    try:
        x = int(input('please enter your discussions scores: '))
        my_list.append(x)
        l.append(x * (2/100))
    except:
        print('you made an error,please try again')
        
print(my_list)
print('your total percentage from discussion scores is: '+ str(sum(l)))
The same thing can be done with the following two loops on my_list2 and s
Reply


Messages In This Thread
RE: help me make this code better please (basic) - by melifaro09 - Jun-08-2020, 12:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Please help to make the code smaller dexomol 2 3,217 Feb-26-2021, 09:56 PM
Last Post: dexomol

Forum Jump:

User Panel Messages

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