Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How could I show the cost of a game using Python, using code something like this:
if game_list[game]>= 10:
print ("The Price for this Game is: $"), game_prices[game]*1.1
If this is python3.x you have to do it as follows:
if game_list[game]>= 10:
print ("The Price for this Game is: $", game_prices[game]*1.1)
For python2.7, it would be:
if game_list[game]>= 10:
print "The Price for this Game is: $"+game_prices[game]*1.1
You might be better to delegate the price-setting logic:
def game_price(game):
price = game_list[game]
if price >= 10:
markup = 0.1
else:
markup = 0.2
return price * (1. + markup)
print("The game's price is ${:0.2f}".format(game_price(game)))
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
counttonum = 1
countnum = input("[•] Provide A Number :")
while counttonum < countnum:
print("[", counttonum, "] : Number = ", counttonum)
counttonum +=1
I was trying to make a counting tool that counts up to the provided number from the “input()” function.
For example:
providedNumberFromInput = 5
output = 1
2
3
4
5
And it’ll stop if the provided number is reached. Please help me.
You are very close to solution. Problem is that input() returns value as string so you will need to convert it. And also if you want to include entered number use <= instead of <
while counttonum <= int(countnum):
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a list that named 'ages'. I try this.
for n in ages:
if not n:
continue
a = float(n)
sum1 += a
But that only output lastone of the list. what am I doing wrong?
A little bit change and your sum result will be well
for n in ages:
if not n:
continue
a = float(n) # move left
sum1 += a
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
def thing():
_list = [1,1,5,6,8,3,4,6,10,23,5,12,67,3,25,2,6,5,4,3,2,1]
_list1 = [str(i) for i<=5 in lista]
return " ".join(_list1)
print(thing()))
I am new to this type of list managment, I am trying to put in _list1 only integers that are less then 5
so like the name of your function, it's created to calculate the sum of integers.
So basically, if your n=0 then your program will return 0 as result.
If not (else), it gonna give you a result of the calculation in return.
And here you want to print the interger sum of 451 which will give you the result of n % 10 + integer_sum(int(n / 10))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This is my attempt to make the turtle stop after traveling nearly 400 pixels.
def race():
while True:
alex.forward(r_alex)
a = a + r_alex
if a > 399.9:
break
And this is what I got back
UnboundLocalError: local variable 'a' referenced before assignment
The line a = a + r_alex uses a before you actually define a.
I'm guessing a is the turtle's displacement so perhaps you should try the following:
def race():
a = 0
while True:
alex.forward(r_alex)
a += r_alex
if a > 399.9:
break
Even better:
def race():
a = 0
while(a > 399.9):
alex.forward(r_alex)
a += r_alex
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can't seem to find an answer to this;
For example:
health -= random.randrange(0, 5)
How would I print out (edit: to the the console) what number was selected in the range to show how much health was deducted?
It depends where you want to print it... In addition i hope that you initialized health variable to something and then use -= to decrease it... If you just want to print it to console you have to
print health #python 2.x
or
print(health) #python 3.x
of course you have to store the random number was selected
rand = Random.randrange(0,5)
print rand
What about this:
rand = random.randrange(0, 5)
health -= rand
print rand
if you are on python interpreter command, just type health. It will print it out. If you are doing through code, do
rand = random.randrange(0, 5)
print rand