File tree Expand file tree Collapse file tree
games/Number-Guessing-Game Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77print ("I'm thinking of a number between 1 and 100...\n " )
88
99while True :
10- num = int (input ("🤔 Guess the Number (1 - 100): " ))
10+ try :
11+ num = int (input ("🤔 Guess the Number (1 - 100): " ))
12+ except ValueError :
13+ print ("⚠️ Oops! That doesn't look like a valid number. Please try again.\n " )
14+ continue
1115
1216 if (num >= 1 ) and (num <= 100 ):
1317 if num > num1 :
Original file line number Diff line number Diff line change 11print ("🔢 Happy Number Checker 🔢" )
22print ("🎯 A happy number is a number which eventually reaches 1 when replaced repeatedly by the sum of the square of its digits.\n " )
33
4- N = int (input ("➡️ Enter a number: " ))
4+ while True :
5+ try :
6+ N = int (input ("➡️ Enter a number: " ))
7+ break
8+ except ValueError :
9+ print ("⚠️ Oops! That doesn't look like a valid number. Please try again.\n " )
510
611seen = set ()
712num = N
1217if (num == 1 ):
1318 print (f"🔍 { N } is a happy number! ✅" )
1419else :
15- print (f"🔍 { N } is not a happy number. ❌" )
20+ print (f"🔍 { N } is not a happy number. ❌" )
Original file line number Diff line number Diff line change 3232 print (f"Row { i + 1 } : { row_str .center (max_width )} " )
3333
3434 elif choice == '2' :
35- row_num = int (input (f"\n 📍 Enter row number (1 to { n } ): " ))
36-
37- if 1 <= row_num <= len (triangle ):
35+ try :
36+ row_num = int (input (f"\n 📍 Enter row number (1 to { n } ): " ))
37+ except ValueError :
38+ print ("⚠️ Oops! That doesn't look like a valid number. Please try again." )
39+ row_num = None
40+
41+ if row_num is not None and 1 <= row_num <= len (triangle ):
3842 print (f"\n 📍 Row { row_num } of Pascal's Triangle:" )
3943 print (f" { triangle [row_num - 1 ]} " )
4044 print (f"\n 📊 Elements: { ' → ' .join (map (str , triangle [row_num - 1 ]))} " )
41- else :
45+ elif row_num is not None :
4246 print (f"\n ❌ Row { row_num } doesn't exist in the generated triangle!" )
43-
44- else :
45- print ("❌ Invalid choice!" )
47+
48+ else :
49+ print ("❌ Invalid choice!" )
4650
4751 print (f"\n 💡 Total rows generated: { n } " )
4852
You can’t perform that action at this time.
0 commit comments