-
Notifications
You must be signed in to change notification settings - Fork 16.9k
/
Copy pathmatch_case.py
60 lines (49 loc) · 1.68 KB
/
match_case.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
Checking City Location
'''
usa = ["atlanta", "new york", "chicago", "baltimore"]
uk = ["london", "bristol", "cambridge"]
india = ["mumbai", "delhi", "bangalore"]
city = input("Enter city name: ").lower()
match city:
case city if city in usa:
print(f"{city} is in USA")
case city if city in uk:
print(f"{city} is in UK")
case city if city in india:
print(f"{city} is in India")
case _:
print(f"I won't be able to tell you which country {city} is in! Sorry!")
'''
Comparing Two Cities
'''
usa = ["atlanta", "new york", "chicago", "baltimore"]
uk = ["london", "bristol", "cambridge"]
india = ["mumbai", "delhi", "bangalore"]
city1 = input("Enter city 1: ").lower()
city2 = input("Enter city 2: ").lower()
match (city1, city2):
case (city1, city2) if city1 in usa and city2 in usa:
print("Both cities are in USA")
case (city1, city2) if city1 in uk and city2 in uk:
print("Both cities are in UK")
case (city1, city2) if city1 in india and city2 in india:
print("Both cities are in India")
case _:
print("They don't belong to the same country")
'''
Identifying Cuisine
'''
indian = ["samosa", "kachori", "dal", "naan"]
chinese = ["egg roll", "fried rice", "pot sticker"]
italian = ["pizza", "pasta", "risotto"]
dish = input("Enter a dish name: ").lower()
match dish:
case dish if dish in indian:
print(f"{dish} is an Indian cuisine")
case dish if dish in chinese:
print(f"{dish} is a Chinese cuisine")
case dish if dish in italian:
print(f"{dish} is an Italian cuisine")
case _:
print(f"Based on whatever little knowledge I've, I can't tell which cuisine {dish} is")