username5364012
Badges: 9
Rep:
?
#1
Report Thread starter 1 month ago
#1
I edited this thread
Last edited by username5364012; 4 weeks ago
1
reply
theJoyfulGeek
Badges: 20
Rep:
?
#2
Report 1 month ago
#2
From what I can figure out from your post (as python code)
plane_bodies = [mN, mW, lN]
plane_bod_cap = [180, 406, 220]
plane_first_min = [8, 14, 10]
num = input("How many first class seats are on the plane?"
plane = input("What type of plane is it. 0 = medium nar, 1= medium wide, 2 = large narrow")
if num != 0:
if num < plane_first_min[int(plane)]:
num = input("Please enter a suitable number.")
elif num > 0.5 * plane_bod_cap[int(plane)]:
num = input("Please input a suitable number.")
else:
print("You have entered a suitable number yay!")

Warning - this code does not have any tabs, blank space, etc. Those are necessary for python. You need to add them yourself.

I hope this helps! It should work (hopefully). I'm not completely sure what you meant by 2 - if it's not correct, you can change it.
1
reply
username5364012
Badges: 9
Rep:
?
#3
Report Thread starter 1 month ago
#3
(Original post by Spider78)
Thank you so much, I really couldn't do this by myself. Sorry about the 2 - it was a typo
Everything works fine but the only issue is that it keeps saying that < is not compatible with int. I have had this problem before but I have no idea how to fix it; if you are not sure as well I will try to post another question - thanks again for your help anyway!
Last edited by username5364012; 1 month ago
0
reply
gyuigygh
Badges: 10
Rep:
?
#4
Report 1 month ago
#4
(Original post by Spider78)
Everything works fine but the only issue is that it keeps saying that < is not compatible with int. I have had this problem before but I have no idea how to fix it; if you are not sure as well I will try to post another question - thanks again for your help anyway!
You must convert to an int. When you get an input it is automatically string.

So every time you do an input for a number
Instead of:
num = input("blah blah blah")
Change it to:
num =int(input("blah blah blah"))

By wrapping the input in int() it casts it to an integer. We must do this as you can't check if a a string such is "10" is less than an integer value but we can check if an int such as 10 is less than an integer value.
Last edited by gyuigygh; 1 month ago
0
reply
gyuigygh
Badges: 10
Rep:
?
#5
Report 1 month ago
#5
(Original post by Spider78)
When I did that, the program started crashing more and it kept saying that whatever numbers I entered were invalid. So this what I have coded so far. Feel free to correct me - thanks for your help!
def flightDetails():
Aircraft = int(input("Please enter the type of aircraft used: 1 = medium narrow body, 2 = large narrow body 3 = medium wide body: ")))

while Aircraft not in (1,2,3):
print("Invalid answer - Please re-enter")
Aircraft = int(input("Please enter the type of aircraft used:\n1 = medium narrow body \n2 = large narrow body 3 = medium wide body:")))

if Aircraft == 1:
print("The running cost per seat per 100km is £8 /n The maximum flight range is 2650km /n The capacity if all seats are standard class is 180 /n The minimum number of first class seats is 8")
elif Aircraft == 2:
print("The running cost per seat per 100km is £7 /n The maximum flight range is 5600km /n The capacity if all seats are standard class is 220 /n The minimum number of first class seats is 10")
elif Aircraft == 3:
print("The running cost per seat per 100km is £5 /n The maximum flight range is 4060km /n The capacity if all seats are standard class is 406 /n The minimum number of first class seats is 14")

plane_bodies = ("medium narrow body","large narrow body","medium wide body")
plane_bod_cap = [180, 220, 406]
plane_first_min = [8, 10, 14]
num = int(input("Please enter the number of first class seats on the plane: "))

if num != 0:
if num < plane_first_min[int(float(Aircraft))]:
num = input("Please enter a suitable number: ")
elif num > 0.5 * plane_bod_cap[int(float(Aircraft))]:
num = input("Please enter a suitable number: ")
else:
print("you have entered a suitable number")
Its crashing coz you changed to comparing strings with things like Aircraft == "1" instead of Aircraft==1

Technucally you can keep those that way but if you're comparing you will need to change to int.

Ive made changes in the above code in bold. Also, please don't make a variable name start with a capital letter unless its a constant, as those are mainly for classes (which you'll learn about when you do comp sci alevel).
Last edited by gyuigygh; 1 month ago
0
reply
gyuigygh
Badges: 10
Rep:
?
#6
Report 1 month ago
#6
(Original post by gyuigygh)
Its crashing coz you changed to comparing strings with things like Aircraft == "1" instead of Aircraft==1

Technucally you can keep those that way but if you're comparing you will need to change to int.

Ive made changes in the above code in bold. Also, please don't make a variable name start with a capital letter unless its a constant, as those are mainly for classes (which you'll learn about when you do comp sci alevel).
Ignore the \n s that's i put
Last edited by gyuigygh; 1 month ago
0
reply
gyuigygh
Badges: 10
Rep:
?
#7
Report 1 month ago
#7
(Original post by Spider78)
plane_bodies = ("medium
if num != 0:
if num < plane_first_min[int(float(Aircraft))]:
num = input("Please enter a suitable number: ")
elif num > 0.5 * plane_bod_cap[int(float(Aircraft))]:
num = input("Please enter a suitable number: ")
else:
print("you have entered a suitable number")
Also, change this part to:

plane_bodies = ("medium
if num != 0:
if num < plane_first_min[Aircraft]:
num = int(input("Please enter a suitable number: "))
elif num > 0.5 * float(plane_bod_cap[Aircraft]) :
num = int(input("Please enter a suitable number: "))
else:
print("you have entered a suitable number")
Last edited by gyuigygh; 1 month ago
0
reply
username5364012
Badges: 9
Rep:
?
#8
Report Thread starter 1 month ago
#8
(Original post by gyuigygh)
Ignore the \n s that's i put
Thanks so much, it works now!
0
reply
gyuigygh
Badges: 10
Rep:
?
#9
Report 1 month ago
#9
(Original post by Spider78)
Thanks so much, it works now!
Are you sure it works properly?
If you say so.
But try entring a invalid value for the number of seats to see if allows you to enter another number and restart the process.

Also, if this is for gcse then i recommend learning about dictionaries or 2d lists as by using these it will make it easier if you wanted to add another aircraft. And it will make your code shorter.
0
reply
username5364012
Badges: 9
Rep:
?
#10
Report Thread starter 1 month ago
#10
(Original post by gyuigygh)
Are you sure it works properly?
If you say so.
But try entring a invalid value for the number of seats to see if allows you to enter another number and restart the process.

Also, if this is for gcse then i recommend learning about dictionaries or 2d lists as by using these it will make it easier if you wanted to add another aircraft. And it will make your code shorter.
Actually, when I enter an invalid answer it doesn't say anything and it won't restart the process - I just got rather excited that it finally said what I wanted it to when entered 0. I still need to enter an equation to it which is: capacity if all seats are standard class - number of first class seats * 2 however I can't start coding that until I get this first bit right!
0
reply
gyuigygh
Badges: 10
Rep:
?
#11
Report 1 month ago
#11
(Original post by Spider78)
Actually, when I enter an invalid answer it doesn't say anything and it won't restart the process - I just got rather excited that it finally said what I wanted it to when entered 0. I still need to enter an equation to it which is: capacity if all seats are standard class - number of first class seats * 2 however I can't start coding that until I get this first bit right!
Can I have screenshot of code so I can have better look at indentation, but my guess is you will have to use a while loop where you get the number of seats, in case they enter wrong one.
0
reply
gyuigygh
Badges: 10
Rep:
?
#12
Report 1 month ago
#12
(Original post by Spider78)
I attached it here
Change the last block of code to the following.
I added a while loop so it keeps asking until they get it right. I also added a line that makes them enter again in case they entered 0.
Name:  Screenshot_20200806_124529_com.sololearn.jpg
Views: 6
Size:  44.9 KB
0
reply
username5364012
Badges: 9
Rep:
?
#13
Report Thread starter 1 month ago
#13
It keeps on repeating - I think that it should say it is a suitable number when 0 is entered
0
reply
gyuigygh
Badges: 10
Rep:
?
#14
Report 1 month ago
#14
(Original post by Spider78)
It keeps on repeating - I think that it should say it is a suitable number when 0 is entered
Oh, if you want it to accept 0 as a suitable number then change the bit in the last else to set valid to True so it stops running the loop:
Name:  Screenshot_20200806_135512_com.sololearn.jpg
Views: 6
Size:  37.3 KB
0
reply
gyuigygh
Badges: 10
Rep:
?
#15
Report 1 month ago
#15
(Original post by Spider78)
Ok thanks it works now - I have one more question : how do I add the equation, capacity of standard seats - number of first class seats * 2 depending on the type of aircraft that is chosen by the user?
Equations have an equal sign. Where is yours?

Are you trying to calculate the running cost.

Do you mean:

cost = capacity of standard seats - number of first class seats * 2

If so then you will have to either make another if-else structure that checks the value of airplane and calculate the cost. Or you can restructure the program to hold the information for the airplanes in a 2d list or dictionary which is better and means less code.
Last edited by gyuigygh; 1 month ago
1
reply
username5364012
Badges: 9
Rep:
?
#16
Report Thread starter 1 month ago
#16
(Original post by gyuigygh)
Equations have an equal sign. Where is yours?

Are you trying to calculate the running cost.

Do you mean:

cost = capacity of standard seats - number of first class seats * 2

If so then you will have to either make another if-else structure that checks the value of airplane and calculate the cost. Or you can restructure the program to hold the information for the airplanes in a 2d list or dictionary which is better and means less code.
Yeah I did mean that sorry - I do try the if / else structure again
0
reply
username5364012
Badges: 9
Rep:
?
#17
Report Thread starter 1 month ago
#17
(Original post by Spider78)
Yeah I did mean that sorry - I do try the if / else structure again
I did it and my subroutine completely works - thanks again for your help!
0
reply
gyuigygh
Badges: 10
Rep:
?
#18
Report 1 month ago
#18
(Original post by Spider78)
I did it and my subroutine completely works - thanks again for your help!
np

If you didn't want to create a new if else structure you could just use the one you already had to store the values (which would also mean you only need 1 print statemet instead of 3), then just add the equation at the end:
Name:  kidcode.png
Views: 7
Size:  69.1 KB
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

With no certainty that exams next year wil take place, how does this make you feel?

More motivated (26)
31.33%
Less motivated (57)
68.67%

Watched Threads

View All