simple python questions

Chat about Linux in general
Post Reply
charroo
Level 3
Level 3
Posts: 165
Joined: Mon Aug 14, 2017 9:45 am
Location: IL

simple python questions

Post by charroo » Mon May 28, 2018 3:13 am

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)

charroo
Level 3
Level 3
Posts: 165
Joined: Mon Aug 14, 2017 9:45 am
Location: IL

Re: simple python questions

Post by charroo » Mon May 28, 2018 3:19 am

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?

User avatar
xenopeek
Level 24
Level 24
Posts: 22469
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: simple python questions

Post by xenopeek » Mon May 28, 2018 3:20 am

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 3
Level 3
Posts: 165
Joined: Mon Aug 14, 2017 9:45 am
Location: IL

Re: simple python questions

Post by charroo » Mon May 28, 2018 3:39 am

:mrgreen:

Hoser Rob
Level 11
Level 11
Posts: 3973
Joined: Sat Dec 15, 2012 8:57 am

Re: simple python questions

Post by Hoser Rob » 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.

User avatar
killer de bug
Level 14
Level 14
Posts: 5390
Joined: Tue Jul 08, 2008 1:49 pm
Location: Graz, Austria

Re: simple python questions

Post by killer de bug » 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:
Image
If it ain't broke, fix it until it is.

charroo
Level 3
Level 3
Posts: 165
Joined: Mon Aug 14, 2017 9:45 am
Location: IL

Re: simple python questions

Post by charroo » Wed May 30, 2018 7:12 am

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.

charroo
Level 3
Level 3
Posts: 165
Joined: Mon Aug 14, 2017 9:45 am
Location: IL

Re: simple python questions

Post by charroo » Wed May 30, 2018 7:21 am

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?

User avatar
killer de bug
Level 14
Level 14
Posts: 5390
Joined: Tue Jul 08, 2008 1:49 pm
Location: Graz, Austria

Re: simple python questions

Post by killer de bug » Wed May 30, 2018 12:12 pm

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.
Image
If it ain't broke, fix it until it is.

charroo
Level 3
Level 3
Posts: 165
Joined: Mon Aug 14, 2017 9:45 am
Location: IL

Re: simple python questions

Post by charroo » Thu May 31, 2018 2:42 am

ok, thanks

when i'm at the end of chapter 3 and if having problems with the tasks i will post my questions here

User avatar
killer de bug
Level 14
Level 14
Posts: 5390
Joined: Tue Jul 08, 2008 1:49 pm
Location: Graz, Austria

Re: simple python questions

Post by killer de bug » Thu May 31, 2018 5:40 am

You can learn easily python with this free book: http://greenteapress.com/thinkpython2/thinkpython2.pdf
Image
If it ain't broke, fix it until it is.

Post Reply

Return to “Chat about Linux”