0

Python

How to calculate tuition and look into the error of my code pleeeaaassse. https://code.sololearn.com/c9LAcg0PEvZr/?ref=app

13th Feb 2019, 5:19 AM
Safina Nganga
Safina Nganga - avatar
9 ответов
+ 4
The error in your code was triggered from courseid[''] this is not right, list element can't be referenced by string, only index or slice (From the error message). I suggest to check whether input for <course> is valid by checking first if there's such course Id enlisted in <courseid> list. I'm not sure what to suggest about tuition calculation, you can explain how you want the calculation done? what factors affect the tuition cost? courseid=['cs101','cs201','cs301'] number_credits={'cs101':4,'cs201':4,'cs301':4} TUITION=600.0 print("Select a class from",courseid) course=input('') if course in courseid: # check for valid course print("You are taking",course,"which is",number_credits[course],"credits costing you",TUITION) else: print(f'Invalid class selection {course}')
13th Feb 2019, 5:50 AM
Ipang
+ 4
Alright, but then which part of the calculation you need help with? and I'm sorry but I'm not following your explanation of the calculation really well, I'm having difficulty trying to understand you ...
13th Feb 2019, 6:20 AM
Ipang
+ 3
What's that 600* I don't get it ...
13th Feb 2019, 6:04 AM
Ipang
+ 3
Safina Nganga I see you have posted a new question with this topic, then I suppose you can delete this one and stick with the new one, to reduce duplicate threads. Good luck 👍
14th Feb 2019, 3:40 AM
Ipang
+ 2
Safina Nganga Can you please describe the problem and what you're trying to do in full sentences? You're only giving fragmentary information which makes it very difficult to understand what you're trying to achieve
13th Feb 2019, 6:22 AM
Anna
Anna - avatar
0
ok for tuition its in number of credits and the cost per credit which is that constant 200
13th Feb 2019, 5:56 AM
Safina Nganga
Safina Nganga - avatar
0
600*
13th Feb 2019, 5:56 AM
Safina Nganga
Safina Nganga - avatar
0
a constant for the credits per hour 600.0
13th Feb 2019, 6:14 AM
Safina Nganga
Safina Nganga - avatar
0
ok you have the list which contains courseid then you have a dictionary which contains the corseid which corresponds with the number of credits for that courseid then you have the tuition in credits per hour which is a constant 600 its suppose print that you choose a courseid then display the following message after “You are taking, courseid, “which is, number_credits, “ credits costing you”,TUITION how do i calculate the tuition with my code above so it can print right along with the message and able to select a course id which will then display the above message? https://code.sololearn.com/c9LAcg0PEvZr/?ref=app
13th Feb 2019, 2:40 PM
Safina Nganga
Safina Nganga - avatar