• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Week4 Coding Exercise 15 Adehumble  Feb 22nd, 2020 (edited) 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #15
2. print("This program is written to concatenate nested lists if and only if the list has just 3 elements.")
3. print("|||||"*24)
4.
5. #I am going to be demonstrating the functionality of this code by allowing my user to give me various examples of each classes of food. By so doing, i'll be generating a nested list
6.
7. #My Function Program
8. def fancy_concatenate(user_list):
10.     for l in user_list:
11.         if len(l)!=3:
12.             continue
15.
16.
17. #My Main Program
18. universal_list=[]
19. carb=[]
20. protein=[]
21. fat_and_oil=[]
22. vitamins=[]
23. water=[]
24. minerals=[]
25. fibre=[]
26.
27. #I am going to limit this program to 3 sublists i.e i'll only be considering carbohydrate, protein and vitamins. That was why i purposely comments out the remaining lines of codes.
28.
29. while True:
30.     try:
31.         num=int(input("How many examples of carbohydrate can you tell me? "))
32.         break
33.     except ValueError:
34.         print("Ooopps! That's a wrong input.\nYou must enter a whole number.\nTry again!")
35.         print("|||||"*24)
36.
37. for n in range(num):
38.     c=input("Mention them: ")
39.     carb.append(c)
40. universal_list.append(carb)
41.
42.
43. while True:
44.     try:
45.         num1=int(input("How many examples of protein can you tell me? "))
46.         break
47.     except ValueError:
48.         print("Ooopps! That's a wrong input.\nYou must enter a whole number.\nTry again!")
49.         print("|||||"*24)
50.
51. for n1 in range(num1):
52.     p=input("Mention them: ")
53.     protein.append(p)
54. universal_list.append(protein)
55.
56.
57. while True:
58.     try:
59.         num2=int(input("How many examples of vitamins can you tell :me? "))
60.         break
61.     except ValueError:
62.         print("Ooopps! That's a wrong input.\nYou must enter a whole number.\nTry again!")
63.         print("|||||"*24)
64.
65. for n2 in range(num2):
66.     v=input("Mention them ")
67.     vitamins.append(v)
68. universal_list.append(vitamins)
69.
70. #num3=int(input("How many examples of fats & oil can you tell me? "))
71. #for n3 in range(num3):
72. #   fo=input("Mention them: ")
73. #   fat_and_oil.append(fo)
74. #universal_list.append(fat_and_oil)
75.
76. #num4=int(input("How many examples of fibre can you tell me? "))
77. #for n4 in range(num4):
78. #   f=input("Mention them: ")
79. #   fibre.append(f)
80. #universal_list.append(fibre)
81.
82.
83. #num5=int(input("how many type of minerals do u know? "))
84. #for n5 in range(num5):
85. #   m=input("give me examples: ")
86. #   minerals.append(m)
87. #listo.append(minerals)
88.
89.
90. #num6=int(input("how many type of water do u know? "))
91. #for n6 in range(num6):
92. #   w=input("give me examples: ")
93. #   water.append(m)
94. #listo.append(water)
95.
96.
97. fancy_concatenate(universal_list)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top