0
Python
How to calculate tuition and look into the error of my code pleeeaaassse. https://code.sololearn.com/c9LAcg0PEvZr/?ref=app
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}')
+ 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 ...
+ 3
What's that 600* I don't get it ...
+ 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 👍
+ 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
0
ok for tuition its in number of credits and the cost per credit which is that constant 200
0
600*
0
a constant for the credits per hour 600.0
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