# limt the amout of values in a line

Page 1 of 1

## 3 Replies - 760 Views - Last Post: 14 November 2012 - 02:07 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=297822&amp;s=c0bd00abf6c7971174b52ca704cde403&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 littlePilot

• New D.I.C Head

Reputation: 2
• Posts: 23
• Joined: 07-March 12

# limt the amout of values in a line

Posted 30 October 2012 - 06:11 PM

i want to know how to limt the amount of vales in this bit of code to a value i typed in before in the code

```menu = [('Pricot Chicken', 8.50), ('Meat Lovers', 13.50), ('Vegetarian', 13.50), ('Double Cheese', 13.50), ('Hawaiian', 13.50), ('Pepperoni', 8.50), ('Beef and Onion', 8.50), ('Ham and Cheese', 8.50), ('Tomato Margherita', 8.50), ('Classic Italian', 8.50), ('BBQ Chicken and Bacon', 8.50), ('Italian Veg', 8.50)]

while True:
try:
num_pizzas= int (input('How meny pizzas do u want to buy?'))
if num_pizzas in (range (1, 6)):
break
elif num_pizzas not in (range (1, 6)):
pass
except ValueError:
pass
print ("Please enter number under 5")

fmt, nfmt = '{0:<30} {1:>9} {2:>9}'.format, '{0:0.2f}'.format

print('\n'.join('{0:>3}. {1:<30} {2:>9}'.format(i+1, name, nfmt(price)) for i, (name, price) in enumerate(menu)))

print ("What pizzas would you like to order? separated by a space")
order = sorted([ i for i in (int(s)-1 for s in input().split() if s.isdigit()) if i in range(len(menu)) ]) # i want to limt this to the amout num_pizzas
```

Is This A Good Question/Topic? 0

## Replies To: limt the amout of values in a line

### #2 Tayacan

• D.I.C Regular

Reputation: 145
• Posts: 275
• Joined: 18-January 11

## Re: limt the amout of values in a line

Posted 31 October 2012 - 02:46 AM

Well. You're asking the user to input his choices on one line, so clearly, you can't limit the amount of numbers he can enter. That gives you two options. One, you can simply take the number of values that you want, and ignore the rest. That's not very nice to the costumer, though.

The other option is to have the user input his choices one at a time, and only ask as many times as you want. I'd do that with a for loop.
```for i in range(num_pizzas):
```

### #3 darek9576

• D.I.C Lover

Reputation: 203
• Posts: 1,735
• Joined: 13-March 10

## Re: limt the amout of values in a line

Posted 31 October 2012 - 03:16 AM

What is the point in having :

if number in range()
elif number not in range()

Use an else clause.

### #4 littlePilot

• New D.I.C Head

Reputation: 2
• Posts: 23
• Joined: 07-March 12

## Re: limt the amout of values in a line

Posted 14 November 2012 - 02:07 PM

i tryed to use the
```for i in range (num_pizzas)
```
but i just couldn't get it to work like i wanted it too... how do i get that one variable to = so meany different pizzas

```menu = [('Pricot Chicken', 8.50), ('Meat Lovers', 13.50), ('Vegetarian', 13.50), ('Double Cheese', 13.50), ('Hawaiian', 13.50), ('Pepperoni', 8.50), ('Beef and Onion', 8.50), ('Ham and Cheese', 8.50), ('Tomato Margherita', 8.50), ('Classic Italian', 8.50), ('BBQ Chicken and Bacon', 8.50), ('Italian Veg', 8.50)]

fmt, nfmt = '{0:<30} {1:>9} {2:>9}'.format, '{0:0.2f}'.format

print('\n'.join('{0:>3}. {1:<30} {2:>9}'.format(i+1, name, nfmt(price)) for i, (name, price) in enumerate(menu)))

print ("What pizzas would you like to order? separated by a space")

for i in range (num_pizza):
order = sorted([ i for i in (int(s)-1 for s in input().split() if s.isdigit()) if i in range(len(menu)) ])

print (("order for"),name1)
print(fmt('Item', 'Price', 'Total'))
total = 0.0
for i in order:
name, price = menu[i]
total += price
print(fmt(name, nfmt(price), nfmt(total)))
print(fmt('Grand Total','', nfmt(total + d_or_p)))
if d_or_p == 'yes':

print ("Thanks for using Ethans python code thank you come agian")

next_order = int(input("would u like to cancel or make another order?"))
```

im just confusing myself more and more lol