lichess.org
Donate

Umm guys my python command doesn't work :(

I had to do a coded calculator for a pet shop (pls no jokes about that) but i messed up commands see

/number_of_packets_of_food-for_dogs
number_of_packets_of_food_for_cats
final_price_of_all_packets_food_for_dogs = number_of_packets_of_food_for_dogs * 2.50
final_price_of_all_packets_food_for_cats = number_of_packets_of_food_for_cats * 4
print(f'{final_price_of_all_packets_food_for_dogs} lv.')
print(f'{final_price_of_all_packets_food_for_cats} lv.')

project finished with exit code 1 error traceback

C:\Users\User\PycharmProjects\MyFirstProject\venv\Scripts\python.exe C:/Users/User/PycharmProjects/MyFirstProject/Yasen/pet_shop.py
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\MyFirstProject\Yasen\pet_shop.py", line 1, in <module>
number_of_packets_of_food-for_dogs
NameError: name 'number_of_packets_of_food' is not defined

print(f'') is fine there what should I do?
ps:
I'm using Python pycharm 3.9
Asus rizen 3 AMD laptop
I'm doing programing course 2023 help guys why code command not worked

Thx guys
Dummy code would look like this

number_of_packets_of_food_for_dogs = 10
number_of_packets_of_food_for_cats = 8

final_price_of_all_packets_food_for_dogs = number_of_packets_of_food_for_dogs * 2.5
final_price_of_all_packets_food_for_cats = number_of_packets_of_food_for_cats * 4

print(f'Final price of all packets of food for dogs: {final_price_of_all_packets_food_for_dogs} lv.')
print(f'Final price of all packets of food for cats: {final_price_of_all_packets_food_for_cats} lv.')

I think for your case you need the values to be inputted from the user which would require the use of the "input()" function but before that, you'd need to specify the type of data inputted i.e.: integers, decimal values, characters etc.

A revised version in which the values are to be inputted by the user would be:

# Asks the user for input
number_of_packets_of_food_for_dogs = float(input("Enter the number of packets of food for dogs: "))
number_of_packets_of_food_for_cats = float(input("Enter the number of packets of food for cats: "))

# Calculates the final prices
final_price_of_all_packets_food_for_dogs = number_of_packets_of_food_for_dogs * 2.5
final_price_of_all_packets_food_for_cats = number_of_packets_of_food_for_cats * 4

# Prints the results
print(f'Final price of all packets of food for dogs: {final_price_of_all_packets_food_for_dogs} lv.')
print(f'Final price of all packets of food for cats: {final_price_of_all_packets_food_for_cats} lv.')

I've tried to keep it as beginner-friendly as I could. Hope it helped
Stackoverflow about to become obsolete thanks to lichess forums.
@fluffy_cookie said in #2:
> Buddy you messed up while assigning the variables
>
>
>
> Also it is not defined
yeah man, i saw it a bit later.
but thx anyway!
@fluffy_cookie said in #3:
> Dummy code would look like this
>
> number_of_packets_of_food_for_dogs = 10
> number_of_packets_of_food_for_cats = 8
>
> final_price_of_all_packets_food_for_dogs = number_of_packets_of_food_for_dogs * 2.5
> final_price_of_all_packets_food_for_cats = number_of_packets_of_food_for_cats * 4
>
> print(f'Final price of all packets of food for dogs: {final_price_of_all_packets_food_for_dogs} lv.')
> print(f'Final price of all packets of food for cats: {final_price_of_all_packets_food_for_cats} lv.')
>
> I think for your case you need the values to be inputted from the user which would require the use of the "input()" function but before that, you'd need to specify the type of data inputted i.e.: integers, decimal values, characters etc.
>
> A revised version in which the values are to be inputted by the user would be:
>
> # Asks the user for input
> number_of_packets_of_food_for_dogs = float(input("Enter the number of packets of food for dogs: "))
> number_of_packets_of_food_for_cats = float(input("Enter the number of packets of food for cats: "))
>
> # Calculates the final prices
> final_price_of_all_packets_food_for_dogs = number_of_packets_of_food_for_dogs * 2.5
> final_price_of_all_packets_food_for_cats = number_of_packets_of_food_for_cats * 4
>
> # Prints the results
> print(f'Final price of all packets of food for dogs: {final_price_of_all_packets_food_for_dogs} lv.')
> print(f'Final price of all packets of food for cats: {final_price_of_all_packets_food_for_cats} lv.')
>
> I've tried to keep it as beginner-friendly as I could. Hope it helped
thx i managed the task :)
@Roadto2_1k said in #4:
> Stackoverflow about to become obsolete thanks to lichess forums.
was just a question i had bruh
i began typing commands on python yesterday, so...
@RonaldoSaisSui said in #7:
> was just a question i had bruh
> i began typing commands on python yesterday, so...
Ok bruh :thumbsup:

This topic has been archived and can no longer be replied to.