I cannot find the error, I keep getting EOF errors as well as a syntax error!

#So below is my code, however I cannot seem to find the issues! It throws error codes at “def get_energy(mass…”

train_mass = 22680
train_acceleration = 10
train_distance = 100
bomb_mass = 1


# Write your code below: 

#Fahrenheit to Celsius
def f_to_c(f_temp):
  c_temp = (f_temp - 32) * 5/9
  return c_temp
f100_in_celsius = f_to_c(100)
print(f100_in_celsius)

#Celsius to Fahrenheit
def c_to_f(c_temp):
  return c_temp * (9/5) + 32

c0_in_fahrenheit = c_to_f(0)
print(c0_in_fahrenheit)

#Force Equation
def get_force(mass, acceleration):
  return mass * acceleration

train_force = get_force(train_mass, train_acceleration)

print("The GE train supplies " + str(train_force) + " Newtons of force."

def get_energy(mass, c=3*10**8):
  return mass * c**2

bomb_energy = get_energy(bomb_mass)

print(bomb_energy)

print("A 1kg bomb supplies" + str(bomb_energy) + " Joules.")

def get_work(mass, acceleration, distance):
  force = get_force(mass, acceleration)
  return force * distance

train_work = get_work(train_mass, train_acceleration, train_distance)

print("The GE train does" + str(train_work) + " Joules of work over" + str(train_distance) + " meters.")

hi @pphillips5

you may want to check the syntax you wrote. Were there any mistakes? In terms of spelling or indentation.

What is mass x c2 ?

Hi,
You might want to cast your eye over the line just before where the error message is pointing to…
Also, as estforesta to says;
c2 is going to give you a problem as it’s not been assigned anything,
I assume it’s supposed to be c-squared, so you’ll have to look at alternate way of doing that.

Other than that, assuming your indentation is correct (it doesn’t look formatted correctly on here), with those two things altered I got your code running fine.
Feel free to ask if you’re still not sure.

1 Like

Hi there, welcome to the forums.

You’ll notice I’ve edited your post to correctly format your code. Indentation is critical in Python, but the forum will remove extra spaces unless you tell it not to. There’s instructions here on how to correctly format your code when posting. :slight_smile:

You haven’t closed the parentheses for your call to print(). :slight_smile:

The queries around what appeared to be a variable c2 are due to the lack of correct formatting, since the forum will interpret a non-code ** as an indicator to make the text bold.

Also, the code isn’t returning anything as there are no parentheses after the return. That lesson gave me a hard time too :slight_smile:
-Chuck

Hi guys, please I am stuck. I wrote a code in response to the question

" Write an if statement that checks if the student has enough credits to graduate. If they do, print the string:

“You have enough credits to graduate!”

Can a student with 120 credits graduate from Calvin Coolidge’s Cool College?.

My code is as seen below;

user_credit = input ("Enter credit score")
if user_credit >= 120:
  print("You have enough credits to graduate")
else:
  print("Sorry, you didn't make it this time, but that's ok. There's another session")

THE PROBLEM: It keeps showing me EOF error pointing at line one. Please help. I have compared with the solution, and we used different approach (see attached) so it didn’t help me.

PS: My code starts from line 10 , and the solution started from line 13

Likely that the exercise you’re attempting does not have an interactive terminal, just an output device.

If you can’t provide the input, you’ll get that error.

From memory, you’re meant to put the credits into a variable and check that rather than ask for input from the shell. This matches with what the solution is showing you.

TL;DR: Your use of input() is the problem.

1 Like