I'm new to python, and I'm trying here to make some math, in Quanity, and balance. But that function in define, don't do anything to balance, and quanity. When I print them they are still the stock.
Ballance = 7000 # 7K DEMO
# SANDELYS
Indica_WEED_QUANITY = 600
AMAZON_QUANITY = 18
STEAM_GIFT50_QUANITY = 4
# Price
STEAM_GIFT50_PRICE_PER1 = 50 # Each
Indica_WEED_PRICE_PER1 = 8
Amazon_Prime_PRICE_PER1 = 25 # Each
def PickForShopItem():
ShopPick = int(input("~ PRODUCT ID = "))
if ShopPick == 1:
clear()
while True:
Pasirinxm = input("Would You like to continue buying ~ Indica WEED KUSH * ?\n* Y/N: ")
if "Y" in Pasirinxm or "y" in Pasirinxm:
clear()
BuyKiekis = int(input("~ How many you would to buy of " + Indica_WEED_NAME + "?\n "))
Indica_WEED_QUANITY - BuyKiekis # Atimam Ir paliekam sandari mazesni
Bendra_Suma = ( BuyKiekis * Indica_WEED_PRICE_PER1)
print(Bendra_Suma)
Ballance = 500
print(Ballance - Bendra_Suma)
print("Sandelio Kiekis po pirkimo " + str(Indica_WEED_QUANITY))
print(Ballance)
break
elif "N" in Pasirinxm or "n" in Pasirinxm:
print("xuine iseina")
break
elif " " in Pasirinxm or len(Pasirinxm) < 1:
print("PLease dont do shit")
continue
break
elif ShopPick == 2:
print("Darai")
elif ShopPick == 3:
print("hgelo")
Indica_WEED_NAME = "~ Indica WEED KUSH *
I think the problem you have is that:
Indica_WEED_QUANITY - BuyKiekis
does not update the variable "Indica_WEED_QUANITY" (and you have the same problem in the line print(ballance - BendraSuma))
In Python, that statement will just work out a value, but you aren't telling the program to save or store it anywhere. Do this:
Indica_WEED_QUANITY = Indica_WEED_QUANITY - BuyKiekis
Python also allows you to do this with a -= operator:
Indica_WEED_QUANITY -= BuyKiekis
will update Indica_WEED_QUANITY by subtracting the BuyKeikis amounts.
Related
I am a beginner in Python and I think I need some help with my program. Any kind of help or advice would be appreciated:)
You can see the program below, when I run it it gets stuck on the part of comparing the random ticket with the winning ticket(win_combination).
from random import choice
#Winning ticket
win_combination = input("Enter the winning combination of 4 numbers(1-digit-numbers): ")
while len(win_combination) != 4:
if len(win_combination) > 4:
win_combination = input("Reenter a shorter combination(4 one-digit-numbers): ")
elif len(win_combination) < 4:
win_combination = input("Reenter a longer combination(4 one-digit-numbers): ")
print(f"Winning combination is {win_combination}.")
#Specifying range of numbers to choose from
range = range(0, 10)
#Making a fake comparison-ticket to start of the loop
random_ticket = [0, 0]
random_ticket_string = f"{random_ticket[0]}{random_ticket[1]}{random_ticket[2]}{random_ticket[3]}"
#Params for the loop
n_tries = 0
n_guesses = 1
while random_ticket_string != win_combination:
while n_tries > 4:
random_ticket.clear()
number = choice(range)
random_ticket.append(number)
n_tries += 1
n_guesses += 1
random_ticket_string = f"{random_ticket[0]}{random_ticket[1]}"
if random_ticket_string == win_combination:
chance_to_win = f"{(1 / n_guesses) * 100}%"
print("Estimated percent to win is " + chance_to_win + ", it took " + f"{n_guesses} to match the winning combination.")
else:
n_tries = 0
I just started making a game like thing, and for some reason, the elif loop isn't doing anything when "upgrade" is entered.
choclate = 0
multiplier = 1
multipliercost = 10
x = 1
while x == 1:
if input() == (("choclate") + str(choclate+multiplier)):
choclate = choclate+multiplier
print("\nYou now have " + str(choclate) + " choclate.\nMultiplier Upgrade Cost: " + str(multipliercost) + " choclate\n")
elif input() == "upgrade":
multiplier = multiplier*2
choclate = choclate-multipliercost
multipliercost = multipliercost*2.5
print("You have upgraded your multiplier to " + str(multiplier))
I am very new to coding, so I don't really know what to call this problem.
If you call input() twice, then the user needs to key in twice in each round.
if you expect the user to key in only once, then you also need to call input() once in each round, and store it into a variable.
Here is the fix.
choclate = 0
multiplier = 1
multipliercost = 10
x = 1
while x == 1:
# save the input into variable
key_in = input()
print(("choclate") + str(choclate+multiplier))
if key_in == (("choclate") + str(choclate+multiplier)):
choclate = choclate+multiplier
print("\nYou now have " + str(choclate) + " choclate.\nMultiplier Upgrade Cost: " + str(multipliercost) + " choclate\n")
elif key_in == "upgrade":
multiplier = multiplier*2
choclate = choclate-multipliercost
multipliercost = multipliercost*2.5
print("You have upgraded your multiplier to " + str(multiplier))
I am doing a University project to create a plan ordering ticket program, so far these are what I have done:
First, this is the function finding the seat type:
def choosingFare():
print("Please choose the type of fare. Fees are displayed below and are in addtion to the basic fare.")
print("Please note choosing Frugal fare means you will not be offered a seat choice, it will be assigned to the ticketholder at travel time.")
listofType = [""] * (3)
listofType[0] = "Business: +$275"
listofType[1] = "Economy: +$25"
listofType[2] = "Frugal: $0"
print("(0)Business +$275")
print("(1)Economy +$25")
print("(2)Frugal: $0")
type = int(input())
while type > 2:
print("Invalid choice, please try again")
type = int(input())
print("Your choosing type of fare is: " + listofType[type])
if type == 0:
price1 = 275
else:
if type == 1:
price1 = 25
else:
price1 = 0
return price1, listofType[type]
And this is a function finding the destination:
def destination():
print("Please choose a destination and trip length")
print("(money currency is in: Australian Dollars: AUD)")
print("Is this a Return trip(R) or One Way trip(O)?")
direction = input()
while direction != "R" and direction != "O":
print("Invalid, please choose again!")
direction = input()
print("Is this a Return trip(R) or One Way trip(O)?")
if direction == "O":
print("(0)Cairns oneway: $250")
print("(2)Sydney One Way: $420")
print("(4)Perth One Way: $510")
else:
print("(1)Cairns Return: $400")
print("(3)Sydney Return: $575")
print("(5)Perth Return: $700")
typeofTrip = [""] * (6)
typeofTrip[0] = "Cairns One Way: $250"
typeofTrip[1] = "Cairns Return: $400"
typeofTrip[2] = "Sydney One Way: $420"
typeofTrip[3] = "Sydney Return: $575"
typeofTrip[4] = "Perth One Way: $510"
typeofTrip[5] = "Perth Return: $700"
trip = int(input())
while trip > 5:
print("Invalid, please choose again")
trip = int(input())
if trip == 0:
price = 250
else:
if trip == 1:
price = 400
else:
if trip == 2:
price = 420
else:
if trip == 3:
price = 574
else:
if trip == 4:
price = 510
else:
price = 700
print("Your choice of destination and trip length is: " + typeofTrip[trip])
return price, typeofTrip[trip]
And this is the function calculating the total price:
def sumprice():
price = destination()
price1 = choosingFare()
price2 = choosingseat()
sumprice = price1 + price2 + price
print("How old is the person travelling?(Travellers under 16 years old will receive a 50% discount for the child fare.)")
age = float(input())
if age < 16 and age > 0:
sumprice = sumprice / 2
else:
sumprice = sumprice
return sumprice
The error I have:
line 163, in <module> main()
line 145, in main sumprice = sumprice()
line 124, in sumprice
sumprice = price1 + price2 + price
TypeError: can only concatenate tuple (not "int") to tuple
Can someone help me? I am really stuck.
I can't return all the
These functions return 2 values each: destination(), choosingFare(), choosingseat().
Returning multiple values at once returns a tuple of those values:
For example:
return price, typeofTrip[trip] # returns (price, typeofTrip[trip])
So while calculating the sum of all prices, you need to access price, price1, price2 from the tuples:
sumprice = price1[0] + price2[0] + price3[0]
Alternatively: You can edit the code to return list/ dictionary or some other data structure as per your convenience.
First let me explain what happends when you write. return price, typeofTrip[trip].
The above line will return a tuple of two values.
Now for sumprice I think what you want is sum of all prices. So you just want to sum first element of returned values.
This should work for your case.
sumprice = price1[0] + price2[0] + price3[0]
run = 1
list1 = []
for i in range(2):
while run > 0 :
print("-------------------------------------------------------")
run = 1
reg_num = input("Registration Number in caps: ")
tsh = int(input("Hour Entered : "))
tsm = int(input("Minute Entered : "))
tss = int(input("Second Entered : "))
print("")
teh = int(input("Hour Exited : "))
tem = int(input("Minute Exited : "))
tes = int(input("Second Exited : "))
print("Time Entered (camera1)", tsh, ":", tsm, ":", tss, "and Time Exited (camera2)", teh, ":", tem, ":", tes)
if tsh < teh:
tm = (((teh - tsh)*60) + (tem - tsm) +((tes - tss)/60))/60
elif tsh > teh:
teh = 24 + teh
tm = (((teh - tsh)*60) + (tem - tsm) +((tes - tss)/60))/60
speed = run/tm
print("speed of", reg_num, "is", "{:.2f}".format(speed), "mph")
if speed > 70:
list1.append(reg_num)
break
print("Overspeeding vehicles are: ")
for item in list1:
print (item)
this is the code to calculate the speed of a vehicle that passes through a speed camera set 1 mile apart. i have to out put a list of vehicles that are exceeding the speed limit. the problem is when the code calculates the speed (speed = run/time) the error massage states that "tm"(totalminutes) is not defined. can you make some corrections and tell me what is wrong.
The problem is none of your conditions in the 'if' statement are met.
if tsh = teh:
tm = bla
elif tsh < teh:
tm = bla * 2
else:
tm = bla / 2 # Add the 'else' part to do something when all else fails.
I am working on a Hangman game, but I am having trouble replacing the dashes with the guessed letter. The new string just adds on new dashes instead of replacing the dashes with the guessed letter.
I would really appreciate it if anyone could help.
import random
import math
import os
game = 0
points = 4
original = ["++12345","+*2222","*+33333","**444"]
plusortimes = ["+","*"]
numbers = ["1","2","3"]
#FUNCTIONS
def firstPart():
print "Welcome to the Numeric-Hangman game!"
def example():
result = ""
ori = random.choice(original)
for i in range(2,len(ori)):
if i % 2 == 0:
result = result + ori[i] + ori[0]
else:
result = result + ori[i] + ori[1]
return ori
# def actualGame(length):
#TOP LEVEL
firstPart()
play = raw_input("Do you want to play ? Y - yes, N - no: ")
while (play == "Y" and (points >= 2)):
game = game + 1
points = points
print "Playing game #: ",game
print "Your points so far are: ",points
limit = input("Maximum wrong guesses you want to have allowed? ")
length = input("Maximum length you want for the formulas (including symbols) (must be >= 5)? ")
result = "" #TRACE
ori = random.choice(original)
for i in range(2,len(ori)):
if i % 2 == 0:
result = result + ori[i] + ori[0]
else:
result = result + ori[i] + ori[1]
test = eval(result[:-1])
v = random.choice(plusortimes) #start of randomly generated formula
va = random.choice(plusortimes)
formula = ""
while (len(formula) <= (length - 3)):
formula = formula + random.choice(numbers)
formula2 = str(v + va + formula)
kind = ""
for i in range(2,len(formula2)):
if i % 2 == 0:
kind = kind + formula2[i] + formula2[0]
else:
kind = kind + formula2[i] + formula2[1]
formula3 = eval(kind[:-1])
partial_fmla = "------"
print " (JUST TO TRACE, the program invented the formula: )" ,ori
print " (JUST TO TRACE, the program evaluated the formula: )",test
print "The formula you will have to guess has",length,"symbols: ",partial_fmla
print "You can use digits 1 to 3 and symbols + *"
guess = raw_input("Please enter an operation symbol or digit: ")
a = 0
new = ""
while a<limit:
for i in range(len(formula2)):
if (formula2[i] == partial_fmla[i]):
new = new + partial_fmla[i]
elif (formula2[i] == guess):
new[i] = guess
else:
new[i] =new + "-"
a = a+1
print new
guess = raw_input("Please enter an operation symbol or digit: ")
play = raw_input("Do you want to play ? Y - yes, N - no: ")
The following block seems problematic:
elif (formula2[i] == guess):
new[i] = guess
else:
new[i] =new + "-"
Python does not allow modification of characters within strings, as they are immutable (cannot be changed). Try appending the desired character to your new string instead. For example:
elif formula2[i] == guess:
new += guess
else:
new += '-'
Finally, you should put the definition of new inside the loop directly under, as you want to regenerate it after each guess.