simple python questions

Chat about Linux in general
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 6 months after creation.
Locked
charroo
Level 4
Level 4
Posts: 495
Joined: Mon Aug 14, 2017 9:45 am
Location: ISRAEL!

simple python questions

Post by charroo »

how do i fix the error with the total string?

Code: Select all

car_cost = int(input("whats the base price of the car? "))

tax = car_cost * 0.5
license = car_cost * 0.2
prep = 100
destination_charge = 250

print ("Total: " + car_cost + tax + license + prep + destination_charge)
the original question was:
Write a Car Salesman program where the user enters the base
price of a car. The program should add on a bunch of extra fees
such as tax, license, dealer prep, and destination charge. Make
tax and license a percent of the base price. The other fees
should be set values. Display the actual price of the car once
all the extras are applied.
thank you

edit:
is this a good solution?

Code: Select all

car_cost = int(input("whats the base price of the car? "))

tax = car_cost * 0.5
license = car_cost * 0.2
prep = 100
destination_charge = 250

print ("Total: ")
print (car_cost + tax + license + prep + destination_charge)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
i'm on Linux Mint 21.3 Cinnamon
charroo
Level 4
Level 4
Posts: 495
Joined: Mon Aug 14, 2017 9:45 am
Location: ISRAEL!

Re: simple python questions

Post by charroo »

another question that i'm somewhat confused with:
Write a program that allows a user to enter his or her two
favorite foods. The program should then print out the name of
a new food by joining the original food names together.
do i need to make two input functions to assign the name of foods to?
i'm on Linux Mint 21.3 Cinnamon
User avatar
xenopeek
Level 25
Level 25
Posts: 29507
Joined: Wed Jul 06, 2011 3:58 am

Re: simple python questions

Post by xenopeek »

You'd use str.format: https://docs.python.org/3/library/stdty ... str.format

print("Total: {}".format(car_cost + tax + license + prep + destination_charge))

Edit: that's enough cheating on your homework :)
Image
charroo
Level 4
Level 4
Posts: 495
Joined: Mon Aug 14, 2017 9:45 am
Location: ISRAEL!

Re: simple python questions

Post by charroo »

:mrgreen:
i'm on Linux Mint 21.3 Cinnamon
Hoser Rob
Level 20
Level 20
Posts: 11806
Joined: Sat Dec 15, 2012 8:57 am

Re: simple python questions

Post by Hoser Rob »

xenopeek wrote: Mon May 28, 2018 3:20 am Edit: that's enough cheating on your homework :)
+1. WHen you take courses like this it matters if you can actually do the work or not.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
killer de bug

Re: simple python questions

Post by killer de bug »

charroo wrote: Mon May 28, 2018 3:19 am do i need to make two input functions to assign the name of foods to?
Post the code you have already tried and we can help you optimize it. Post working code of course. :wink:
charroo
Level 4
Level 4
Posts: 495
Joined: Mon Aug 14, 2017 9:45 am
Location: ISRAEL!

Re: simple python questions

Post by charroo »

Hoser Rob wrote: Tue May 29, 2018 8:20 am
xenopeek wrote: Mon May 28, 2018 3:20 am Edit: that's enough cheating on your homework :)
+1. WHen you take courses like this it matters if you can actually do the work or not.
i hope that with time i will better understand and be able to find solutions to homework/
Post the code you have already tried and we can help you optimize it. Post working code of course. :wink:
i'll have to think about the question again and try it.
i'm on Linux Mint 21.3 Cinnamon
charroo
Level 4
Level 4
Posts: 495
Joined: Mon Aug 14, 2017 9:45 am
Location: ISRAEL!

Re: simple python questions

Post by charroo »

killer de bug wrote: Wed May 30, 2018 2:25 am
charroo wrote: Mon May 28, 2018 3:19 am do i need to make two input functions to assign the name of foods to?
Post the code you have already tried and we can help you optimize it. Post working code of course. :wink:
question:
Write a program that allows a user to enter his or her two
favorite foods. The program should then print out the name of
a new food by joining the original food names together.

Code: Select all

# enter you favorite foods names

food_1 = input("what's your first favorite food? ")
food_2 = input("what's your second favorite food? ")

print ("you like: " + food_1 + " and " + food_2)
is this a good solution?
i'm on Linux Mint 21.3 Cinnamon
killer de bug

Re: simple python questions

Post by killer de bug »

charroo wrote: Wed May 30, 2018 7:21 am is this a good solution?
No because, you didn't read the question. And as a result, you can't answer it.

I enter pasta and tomato, you should reply pastatomato.
charroo
Level 4
Level 4
Posts: 495
Joined: Mon Aug 14, 2017 9:45 am
Location: ISRAEL!

Re: simple python questions

Post by charroo »

ok, thanks

when i'm at the end of chapter 3 and if having problems with the tasks i will post my questions here
i'm on Linux Mint 21.3 Cinnamon
killer de bug

Re: simple python questions

Post by killer de bug »

You can learn easily python with this free book: http://greenteapress.com/thinkpython2/thinkpython2.pdf
Locked

Return to “Chat about Linux”