This script counts consecutive number strikes of a number that you determine in a number-sequence that you also determine.
I would be very pleased if this script can be reviewed in terms of compactness, readability and quality. If this is perfect, please also let me know. But I am shure it will not be.
import random desired_number = int(input("Desired number: ")) lower_range = int(input("Lower range: ")) upper_range = int(input("Upper range: ")) iterations = int(input("Iterations: ")) consecutive_strikes = 0 biggest_strike = 0 for i in range(iterations): actual_number = random.randint(lower_range, upper_range) print("Actual number: ", actual_number) if actual_number == desired_number: consecutive_strikes += 1 else: if (consecutive_strikes > biggest_strike): biggest_strike = consecutive_strikes consecutive_strikes = 0 # if all numbers are the desired number, the second if-statement in the for-loop # would never be executed if (consecutive_strikes > biggest_strike): biggest_strike = consecutive_strikes print("Biggest consecutive strike: ", biggest_strike)