Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2013, 12:07 AM
anthony415 anthony415 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 anthony415 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #2  
Old January 23rd, 2013, 09:50 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
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.
Comments on this post
anthony415 agrees!
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 23rd, 2013, 10:23 AM
anthony415 anthony415 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 anthony415 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #4  
Old January 23rd, 2013, 10:37 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
In that case post the html page description and have someone other than me answer.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Newbie - combine 2 sets of input

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap