The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Newbie - combine 2 sets of input
Discuss Newbie - combine 2 sets of input in the Python Programming forum on Dev Shed. Newbie - combine 2 sets of input Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 23rd, 2013, 12:07 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 1 h 19 m 49 sec
Reputation Power: 0
|
|
|
Newbie - combine 2 sets of input
I'm new and I've been trying to figure if I have a user input two sets of input; food up to 10 then another drinks.
first set user input
hot dog, hamburger, pizza (up to 10)
second set user input
coke, 7up, sprite, (up to 10)
How can I make output to
1 - hot dog and coke
2 -hot dog and 7up
3 - hot dog and sprite
...then
4 - hamburger and coke
5 - hamburger and 7 up
6 - hamburger and sprite
so on and so on.....
Is there an easier way to script then the following? Also if there's wasn't any input of 10 food or 10 drinks?
food1 = input('Enter food1: ')
food2 = input('Enter food2: ')
food3 = input('Enter food3: ')
food4 = input('Enter food4: ')
food5 = input('Enter food5: ')
food6 = input('Enter food6: ')
food7 = input('Enter food7: ')
food8 = input('Enter food8: ')
food9 = input('Enter food9: ')
food10 = input('Enter food10: ')
drink1 = input('Enter drink1: ')
drink2 = input('Enter drink2: ')
drink3 = input('Enter drink3: ')
drink4 = input('Enter drink4: ')
drink5 = input('Enter drink5: ')
drink6 = input('Enter drink6: ')
drink7 = input('Enter drink7: ')
drink8 = input('Enter drink8: ')
drink9 = input('Enter drink9: ')
drink10 = input('Enter drink10: ')
print(food1, drink1)
print(food1, drink2)
print(food1, drink3)
print(food1, drink4)
print(food1, drink5)
print(food1, drink6)
print(food1, drink7)
print(food1, drink8)
print(food1, drink9)
print(food1, drink10)
print(food2, drink1)
print(food2, drink2)
print(food2, drink3)
print(food2, drink4)
print(food2, drink5)
print(food2, drink6)
print(food2, drink7)
print(food2, drink8)
print(food2, drink9)
print(food2, drink10)
Thanks!
|

January 23rd, 2013, 09:50 AM
|
 |
Contributing User
|
|
|
|
Code:
# python3
# loops, lists, and string formatting will help considerably.
# We'll cover functions next week.
food = list()
drink = list()
print('Note: enter a blank line to progress')
i = 0
edible = 'food'
L = food
while True: # repeat block of statements forever
i += 1 # increment i
prompt = 'Enter {}{}: '.format(edible,i)
s = input(prompt)
s = s.strip()
if not s: # leave the while loop on blank line
break
L.append(s)
print()
i = 0
edible = 'drink'
L = drink
while True: # repeat block of statements forever
i += 1 # increment i
prompt = 'Enter {}{}: '.format(edible,i)
s = input(prompt)
s = s.strip()
if not s: # leave the while loop on blank line
break
L.append(s)
print('\n\nmeal matrix')
for f in food:
print()
for d in drink:
print('{} and {}'.format(f,d))
program run example:
Code:
$ python3 p.py
Note: enter a blank line to progress
Enter food1: dog
Enter food2: chili
Enter food3: worms
Enter food4:
Enter drink1: 7 up
Enter drink2: tequilla
Enter drink3:
meal matrix
dog and 7 up
dog and tequilla
chili and 7 up
chili and tequilla
worms and 7 up
worms and tequilla
Please observe the two while loops are identical. They behave differently because I assigned different values to the variables used within the block before starting the while loop.
__________________
[code] Code tags[/code] are essential for python code!
|

January 23rd, 2013, 10:23 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 1 h 19 m 49 sec
Reputation Power: 0
|
|
|
Thanks!
One more question:
What if I use html for the input then submit the values to the py and use the form.getvalue for the food and drink?
|

January 23rd, 2013, 10:37 AM
|
 |
Contributing User
|
|
|
|
|
In that case post the html page description and have someone other than me answer.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|