Python Forum
Line 42 syntax error..Help!!1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line 42 syntax error..Help!!1
#5
If you have two sets of numbers you can use & to get the intersection (numbers in both sets).
import random

def input_unique_int(min_, max_, used_values =None):
    '''Input a number in range min_ to max_.  used_values is a list of disallowed numbers'''
    while True:
        value = input(f'Enter a number in the range {min_} and {max_} ')
        try:
            value = int(value)
        except ValueError:  # Input is not an integer
            print('Must be an integer number')
            continue
        if value < min_ or value > max_:  # Input is not in range
            print(f'Number must be in range {min_} and {max_}')
            continue
        if used_values is not None and value in used_values :  # Cannot enter values from used_values list
            print(f'That number is already used')
            continue
        return value

winner = random.sample(range(1, 61), 5)
ticket = []
for i in range(len(winner)):
    ticket.append(input_unique_int(1, 60, ticket))

print(f'Winning Numbers: {winner}')
print(f'Your Numbers:  {ticket}')
matches = len(set(winner) & set(ticket))
if matches == len(winner):
    print('You won the lottery!!!!!')
else:
    print(f'You matched {matches} number(s)')
menator01 and naughtyCat like this post
Reply


Messages In This Thread
Line 42 syntax error..Help!!1 - by patpython - Aug-30-2021, 11:12 PM
RE: Line 42 syntax error..Help!!1 - by bowlofred - Aug-30-2021, 11:22 PM
RE: Line 42 syntax error..Help!!1 - by patpython - Aug-30-2021, 11:35 PM
RE: Line 42 syntax error..Help!!1 - by menator01 - Aug-31-2021, 07:08 PM
RE: Line 42 syntax error..Help!!1 - by deanhystad - Sep-01-2021, 03:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,163 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 374 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,563 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,206 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,545 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  syntax error question - string mgallotti 5 1,297 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,243 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 882 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,831 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,360 Jun-18-2022, 01:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020