Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie needs help
#1
Thumbs Up 
Hello guys,

Im just learning Pyhton and doing a code in Replit.. I think Im doing ok so far but Im stuck on a thing that maybe some one here might help me out with?

So im doing this code where a carpurchaser asks someone what type of car/model/year and miles it has.. and they answer like this:
print("What car and modell?")
car = input()

print("What year is the car?")
year = input ()

print("Okey good, how many miles does it got?")
miles = input() 


print(car + " " +  " " + year+ " " + mile)

print("Oh okey, you got a ’car’ of ’model’-modell, and its from ’year’, but has not driven more than ’mile’, sounds intresting!")
the last print does not show when i run the program.. its just says "car" "model" "year".. not what car/year/model/mile i type in the program.. how come? :P

and also.. is there a way to make so it says "miles" after you put the miles numbers in the code?

I hope you guys get what im trying to explain that I need help with ;P

best regards!
Yoriz write Sep-06-2022, 07:21 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
miles = input()
print(car + " " + " " + year+ " " + mile)    #Are they "miles" or "mile"?
Try using f strings
print(f"{car} {year} {miles} miles")
dvejsa likes this post
Reply
#3
(Sep-06-2022, 07:26 PM)XavierPlatinum Wrote:
miles = input()
print(car + " " + " " + year+ " " + mile)    #Are they "miles" or "mile"?
Try using f strings
print(f"{car} {year} {miles} miles")

Thanks bro, it worked! :D

now I only need the "answer part" to work aswell :P
Reply
#4
There are many ways to format output in python. Below are f"strings (preferred) and .format() (older and being replaced by f"strings. Hopefully this is enough to show how you can format your output string.
print(f"{car} {year} {mile}")
print(f"{} {} {}".format(car, year, mile))

Before you start using year or mile as numbers, you'll need to convert them to numbers. For that you'll be using int() and float(). You should also investigate try and except. Inevitably you will enter something that is not a number, and your program will raise a "ValueError" and crash.
dvejsa likes this post
Reply
#5
print(f"Oh okey, you got a {car} of {model}-modell, and its from {year’} but has not driven more than {miles} miles, sounds intresting!")
But you have no input for model
dvejsa likes this post
Reply
#6
(Sep-06-2022, 07:46 PM)Yoriz Wrote:
print(f"Oh okey, you got a {car} of {model}-modell, and its from {year’} but has not driven more than {miles} miles, sounds intresting!")
But you have no input for model

Wow, thanks that is what I was looking for! Heart
Reply


Forum Jump:

User Panel Messages

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