python itertools not printing multiples of 10 - python

In my current python program which shows all possible combinations, it does not show the multiples of 10 (10,20,30,40,etc.) and I don't understand why, I am using the itertools library don't know if there is something that does this? I have looked online and I haven't found anything like it so maybe it has something to do with my installation of it? Anyway, here is the code.
import itertools
from pynput.keyboard import Controller
import time
keyboard = Controller()
loop = True
a = 1
input("Welcome to the Password Possibilities Test")
input("This test will tell you how many possible")
input("combinations a password can have")
input("*all answers must start with an uppercase*")
num_length = 0
alpha_length = 0
sym_length = 0
num = input("So lets start does your password have numbers?\n")
alpha = input("Does it have letters?\n")
sym = input("Does it have symbols?\n")
long = input("Do you know how long the password is?\n")
possibilities = []
if long == "Yes":
length = input("How long is the password?\n")
elif long == "No":
print("Then we will go off of the average password length which is 8\n")
length = 8
if num == "Yes":
num_length = 10
possibilities.append(0)
possibilities.append(1)
possibilities.append(2)
possibilities.append(3)
possibilities.append(4)
possibilities.append(5)
possibilities.append(6)
possibilities.append(7)
possibilities.append(8)
possibilities.append(9)
else:
num_length = 0
if alpha == "Yes":
alpha_length = 52
possibilities.append("a")
possibilities.append("b")
possibilities.append("c")
possibilities.append("d")
possibilities.append("e")
possibilities.append("f")
possibilities.append("g")
possibilities.append("h")
possibilities.append("i")
possibilities.append("j")
possibilities.append("k")
possibilities.append("l")
possibilities.append("m")
possibilities.append("n")
possibilities.append("o")
possibilities.append("p")
possibilities.append("q")
possibilities.append("r")
possibilities.append("s")
possibilities.append("t")
possibilities.append("u")
possibilities.append("v")
possibilities.append("w")
possibilities.append("x")
possibilities.append("y")
possibilities.append("z")
possibilities.append("A")
possibilities.append("B")
possibilities.append("C")
possibilities.append("D")
possibilities.append("E")
possibilities.append("F")
possibilities.append("G")
possibilities.append("H")
possibilities.append("I")
possibilities.append("J")
possibilities.append("K")
possibilities.append("L")
possibilities.append("M")
possibilities.append("N")
possibilities.append("O")
possibilities.append("P")
possibilities.append("Q")
possibilities.append("R")
possibilities.append("S")
possibilities.append("T")
possibilities.append("U")
possibilities.append("V")
possibilities.append("W")
possibilities.append("X")
possibilities.append("Y")
possibilities.append("Z")
else:
alpha_length = 0
if sym == "Yes":
sym_length = 32
possibilities.append("!")
possibilities.append("#")
possibilities.append("#")
possibilities.append("$")
possibilities.append("%")
possibilities.append("^")
possibilities.append("&")
possibilities.append("*")
possibilities.append("(")
possibilities.append(")")
possibilities.append("_")
possibilities.append("+")
possibilities.append("{")
possibilities.append("}")
possibilities.append("|")
possibilities.append(":")
possibilities.append("\\")
possibilities.append("?")
possibilities.append(">")
possibilities.append("<")
possibilities.append("~")
possibilities.append("`")
possibilities.append("[")
possibilities.append("]")
possibilities.append("\"")
possibilities.append(";")
possibilities.append("'")
possibilities.append("/")
possibilities.append(".")
possibilities.append(",")
possibilities.append("`")
else:
sym_length = 0
num_length = int(num_length)
alpha_length = int(alpha_length)
sym_length = int(sym_length)
length = int(length)
calc = num_length + alpha_length + sym_length
final = pow(calc,length)
print("This password has ",final, "possibilities")
input("Click the ENTER key to view all of the combonations")
time.sleep(2)
for i in itertools.combinations_with_replacement(possibilities,length):
print(*i, sep='')
print("This password has ",final, "possibilities")
exit = input("Would you like to exit?\n")
if exit == "Yes":
pass
elif exit == "No":
while loop == True:
a = 1

When you would like to show all possible combinations you mean about the mathematical concept of the permutation with the repetitions. In python in the itertools library there is only permutations that it is like in mathematics the permutation without the repetitions. In python you can use in exchange for it the itertools.product. The full functioning code I enclose below:
import itertools
from pynput.keyboard import Controller
import time
keyboard = Controller()
loop = True
a = 1
input("Welcome to the Password Possibilities Test")
input("This test will tell you how many possible")
input("combinations a password can have")
input("*all answers must start with an uppercase*")
num_length = 0
alpha_length = 0
sym_length = 0
num = input("So lets start does your password have numbers?\n")
alpha = input("Does it have letters?\n")
sym = input("Does it have symbols?\n")
long = input("Do you know how long the password is?\n")
possibilities = []
if long == "Yes":
length = input("How long is the password?\n")
elif long == "No":
print("Then we will go off of the average password length which is 8\n")
length = 8
if num == "Yes":
num_length = 10
possibilities.append("0")
possibilities.append("1")
possibilities.append("2")
possibilities.append("3")
possibilities.append("4")
possibilities.append("5")
possibilities.append("6")
possibilities.append("7")
possibilities.append("8")
possibilities.append("9")
else:
num_length = 0
if alpha == "Yes":
alpha_length = 52
possibilities.append("a")
possibilities.append("b")
possibilities.append("c")
possibilities.append("d")
possibilities.append("e")
possibilities.append("f")
possibilities.append("g")
possibilities.append("h")
possibilities.append("i")
possibilities.append("j")
possibilities.append("k")
possibilities.append("l")
possibilities.append("m")
possibilities.append("n")
possibilities.append("o")
possibilities.append("p")
possibilities.append("q")
possibilities.append("r")
possibilities.append("s")
possibilities.append("t")
possibilities.append("u")
possibilities.append("v")
possibilities.append("w")
possibilities.append("x")
possibilities.append("y")
possibilities.append("z")
possibilities.append("A")
possibilities.append("B")
possibilities.append("C")
possibilities.append("D")
possibilities.append("E")
possibilities.append("F")
possibilities.append("G")
possibilities.append("H")
possibilities.append("I")
possibilities.append("J")
possibilities.append("K")
possibilities.append("L")
possibilities.append("M")
possibilities.append("N")
possibilities.append("O")
possibilities.append("P")
possibilities.append("Q")
possibilities.append("R")
possibilities.append("S")
possibilities.append("T")
possibilities.append("U")
possibilities.append("V")
possibilities.append("W")
possibilities.append("X")
possibilities.append("Y")
possibilities.append("Z")
else:
alpha_length = 0
if sym == "Yes":
sym_length = 32
possibilities.append("!")
possibilities.append("#")
possibilities.append("#")
possibilities.append("$")
possibilities.append("%")
possibilities.append("^")
possibilities.append("&")
possibilities.append("*")
possibilities.append("(")
possibilities.append(")")
possibilities.append("_")
possibilities.append("+")
possibilities.append("{")
possibilities.append("}")
possibilities.append("|")
possibilities.append(":")
possibilities.append("\\")
possibilities.append("?")
possibilities.append(">")
possibilities.append("<")
possibilities.append("~")
possibilities.append("`")
possibilities.append("[")
possibilities.append("]")
possibilities.append("\"")
possibilities.append(";")
possibilities.append("'")
possibilities.append("/")
possibilities.append(".")
possibilities.append(",")
possibilities.append("`")
else:
sym_length = 0
num_length = int(num_length)
alpha_length = int(alpha_length)
sym_length = int(sym_length)
length = int(length)
calc = num_length + alpha_length + sym_length
print(calc)
final = pow(calc,length)
print("This password has ",final, "possibilities")
input("Click the ENTER key to view all of the combonations")
time.sleep(2)
for i in itertools.product(possibilities, repeat = length):
print(*i, sep='')
print("This password has ",final, "possibilities")
exit = input("Would you like to exit?\n")
if exit == "Yes":
pass
elif exit == "No":
while loop == True:
a = 1

Related

input isn't choosing the passwort length

I'm new to programming, and I'm making a password manager.
My problem: -what it does -> when I run the program and enter the length of the password it generates a password, but it is always 4 digits long and the password gets repeated so many times as the digit I had put in.
-What it should do -> the digit that I put in should determine the length of the password and not how many times it gets repeated.
import random
#shuffle the list
def shuffle(string):
tempList = list(string)
random.shuffle(tempList)
return ''.join(tempList)
#the password functions
uppercaseLetter=chr(random.randint(65,90))
lowercaseLetter=chr(random.randint(97,122))
punctuationSign=chr(random.randint(32,152))
digit=chr(random.randint(48,57))
#completing the password
passwordLength = int(input("choose your password length: "))
possibleChars = uppercaseLetter, lowercaseLetter, punctuationSign, digit
ranChar = shuffle(possibleChars)
tempPassword = []
count = 0
while count != passwordLength:
tempPassword.extend(ranChar)
count = count + 1
password = ''.join(tempPassword)
#for which sitename
sitename = input('Save under which name: ')
print (password, sitename)
data=open("test.txt",'a')
data.write(sitename +' ')
data.write(password +'\n')
data.close()
I think you are really over complicating what you need to do, here is what you're trying to do to the best of my knowledge
import random
#completing the password
passwordLength = int(input("choose your password length: "))
temp_pass = ''
count = 0
while count != passwordLength:
char_type = random.randint(0,3)
if char_type == 0:
random_char = chr(random.randint(65,90))
elif char_type == 1:
random_char = chr(random.randint(97,122))
elif char_type == 2:
random_char = chr(random.randint(32,152))
else:
random_char = chr(random.randint(48,57))
temp_pass = temp_pass + random_char
count = count + 1
print(temp_pass)
Hope this helps. I would advise practicing the basics more before trying things like this, there is a lot of bad practises in the code.

Quit while len(int) < 1

I'm new in python, and I'm trying to make a simple quit, if the Input is empty or less then One int.
I'm getting an error which says - ValueError: invalid literal for int() with base 10: '', when entering nothing, just a enter on launch.
import sys
import os
import getpass
def clear(): return os.system('clear')
ballance = 500.00
# Garage Stockas
Wood_InStock = 600
Weed_InStock = 300
Gun_InStock = 15
Gun_Ammo_InStock = 500 * 30 # X30 Total 15000
# Kainos
Gun_Ammo_Price = 15.50
Wood_Price = 3.50
Weed_Price = 9.50
Gun_Price = 250.50
# Produktai
medis = '~ Elemental Wood ~'
weed = '~ Indoor Kush ~'
gun = '~ Shotgun ~'
gun_ammo = '~ Shotgun ammo 30x ~'
# Inventory
Wood_Inventory = 0
Weed_Inventory = 0
Gun_Inventory = 0
Gun_Ammo_Inventory = 0
# No Money
Not_Enough_Money = '~ Sorry you dont have enough money'
while True:
Shop_Pasirinkimas = int(input("~ What would you like to buy?\n1. {medis}\n2. {weed}\n3. {gun}\n".format(medis=medis,weed=weed,gun=gun)))
if len(Shop_Pasirinkimas) < 1:
sys.exit("SOrry")
elif Shop_Pasirinkimas == 1:
clear()
WoodPirkimo_Skaic = int(input("How much {medis} would you like to buy? ".format(medis=medis) + "Wood Now in Stock - {woodins}\n".format(woodins=Wood_InStock)))
# Price per wood - 3.50
ballance -= ( Wood_Price * WoodPirkimo_Skaic)
Wood_Inventory += WoodPirkimo_Skaic
Wood_InStock -= WoodPirkimo_Skaic
print("~ In stock of {}, left {}".format(medis,Wood_InStock))
print("~ Successfully bought {}, Your Ballance is {}\n".format(medis,ballance))
print('Inventory:')
print("~ You have {}, of {}\n".format(Wood_Inventory,medis))
Buymore = input("Would you like to buy anything more?... Yes/No\n")
if "Yes" in Buymore or "yes" in Buymore:
continue
elif "No" in Buymore or "no" in Buymore:
break
else:
break
Let's look at only this part of the code:
while True:
Shop_Pasirinkimas = int(input("~ What would you like to buy?\n1. {medis}\n2. {weed}\n3. {gun}\n".format(medis=medis,weed=weed,gun=gun)))
if len(Shop_Pasirinkimas) < 1:
sys.exit("SOrry")
The empty user input will be passed to int(), but an empty string cannot be converted to an int! So an error is raised.
What you should instead is to not convert the input to int first, and treat it as a string:
while True:
Shop_Pasirinkimas = input("~ What would you like to buy?\n1. {medis}\n2. {weed}\n3. {gun}\n".format(medis=medis,weed=weed,gun=gun))
if len(Shop_Pasirinkimas) < 1:
sys.exit("SOrry")
elif int(Shop_Pasirinkimas) == 1: # convert to int here
clear()
...
int(x,base) function will return the integer object from any number or string. Base defaults to 10. If x is the string, its respective numbers should be within possible values with respect to that base.
As, nothing is entered, it's considered as invalid literal.
Hence, Please use the input as string which can solve the issue easily.
If user doesn't input an integer you will encounter an exception in Shop_Pasirinkimas = int(input(...)). Besides int has no len() so this will also cause error len(Shop_Pasirinkimas). You can do the following to accomplish what you are trying
while True:
try:
Shop_Pasirinkimas = int(input("~ What would you like to buy?\n1. {medis}\n2. {weed}\n3. {gun}\n".format(medis=medis,weed=weed,gun=gun)))
if Shop_Pasirinkimas < 1:
sys.exit("SOrry")
elif Shop_Pasirinkimas == 1:
clear()
WoodPirkimo_Skaic = int(input("How much {medis} would you like to buy? ".format(medis=medis) + "Wood Now in Stock - {woodins}\n".format(woodins=Wood_InStock)))
# Price per wood - 3.50
ballance -= ( Wood_Price * WoodPirkimo_Skaic)
Wood_Inventory += WoodPirkimo_Skaic
Wood_InStock -= WoodPirkimo_Skaic
print("~ In stock of {}, left {}".format(medis,Wood_InStock))
print("~ Successfully bought {}, Your Ballance is {}\n".format(medis,ballance))
print('Inventory:')
print("~ You have {}, of {}\n".format(Wood_Inventory,medis))
Buymore = input("Would you like to buy anything more?... Yes/No\n")
if "Yes" in Buymore or "yes" in Buymore:
continue
elif "No" in Buymore or "no" in Buymore:
break
else:
break
except ValueError:
sys.exit("SOrry")

datetime format over 24 hours

I'm trying to add time and have the output as hh:mm:ss, but when datetime gets over 24 hours it becomes x Days, hh:mm:ss. Is there anyway to only have hh:mm:ss greater than 24 hours?
import datetime
from datetime import timedelta
# intro
print("Welcome to TimeCalc")
print("Calculating Durations")
clear = True
while clear == True:
# first input
firstNumber = True
while firstNumber == True:
time_1 = input("Please enter a time [hh:mm:ss] including 0s: ")
if len(time_1) > 0 and len(time_1) >= 8 and time_1[-6] == ":" and time_1[-3] == ":" and int(time_1[-5:-3]) < 60 and int(time_1[-2:]) < 60:
hours_1 = time_1[:-6]
minutes_1 = time_1[-5:-3]
seconds_1 = time_1[-2:]
hours_1 = int(hours_1)
minutes_1 = int(minutes_1)
seconds_1 = int(seconds_1)
firstNumber = False
else:
print("Invalid Syntax")
time_1 = datetime.timedelta(hours=hours_1, minutes=minutes_1, seconds=seconds_1)
cont = True
while cont == True:
# second input
secondNumber = True
while secondNumber == True:
time_2 = input("Please enter a time to add [hh:mm:ss] including 0s: ")
if len(time_2) > 0 and len(time_2) >= 8 and time_2[-6] == ":" and time_2[-3] == ":" and int(time_2[-5:-3]) < 60 and int(time_2[-2:]) < 60:
hours_2 = time_2[:-6]
minutes_2 = time_2[-5:-3]
seconds_2 = time_2[-2:]
hours_2 = int(hours_2)
minutes_2 = int(minutes_2)
seconds_2 = int(seconds_2)
secondNumber = False
else:
print("Invalid Syntax")
time_2 = datetime.timedelta(hours = hours_2, minutes = minutes_2, seconds = seconds_2)
total = time_1 + time_2
print("The total duration is: " + str(total))
# continue, clear, or exit
choice = input("Continue: Y | Clear: N | Exit: X: ")
if choice == "Y" or choice == "y":
time_1 = total
elif choice == "N" or choice == "n":
cont = False
elif choice == "X" or choice == "x":
quit()
after total variable, can you try to put this code, maybe this is not a super solution but it works
seconds = int(total.total_seconds())
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
print("The total duration is: {h:02d}:{m:02d}:{s:02d}".format(h=hours,
m=minutes, s=seconds))
Use the .strftime() method to format your datetime string.
For example,
>>> import datetime
>>> d = datetime.delta(hours=1)
>>> dt = datetime.datetime(2017,10,30,23,10,10) + d
>>> dt.strftime("%H:%M:%S")
'00:10:10'
Hope it help.

Mastermind Python coding

Ok I have a feeling that this is a simple simple issue but I have been staring at this code for about 10 hours now.
The issue I am having is in mastermind is that once I get it to recognize that I have the correct colors in the right spot I can get it to display the right spots with X and the wrong spots with O. I need to be able to convert that so instead of X and O I need it to tell the user that he/she has 2 blacks and one white
For example: The secret code is RGYB The user enters RGOY so then Python relays "You have 2 blacks(The R and G spots) and one 1 White (The Y because it's the right color just in the wrong index) As of right now I got it to display X for the right color in the right spot and anything else it is an O
I will post what I have been working with now but today I am at my wit's end
https://pastebin.com/HKK0T7bQ
if correctColor != "XXXX":
for i in range(4):
if guess[i] == tempCode[i]:
correctColor += "X"
if guess[i] != tempCode[i] in tempCode:
correctColor += "O"
print (correctColor + "\n")
if correctColor == "XXXX":
if attempts == 1:
print ("You think you are sweet because you got it right on the first try? Play me again!")
else:
print ("Well done... You needed " + str(attempts) + " attempts to guess.")
game = False
A few comments
X and O
you use X and 0 to denote the success, it will be easier and faster to use a list or tuple or booleans for this, that way you can use sum() to count how many colors and locations were correct. Then whether you represent that with X and O or red and white pins is a matter for later
compartmentalization
Your game logic (guess input, input validation, do you want to continue, etc) is mixed with the comparison logic, so it would be best to separate the different functions of your program into different methods.
This is an fineexample to introduce object oriented programming, but is so simple it doesn't need OO, but it can help. What you need is a method which takes a series of colours and compares it to another series of colours
Standard library
Python has a very extended standard library, so a lot of stuff you want to do probably already exists
Correct colours
to count the number of letters which occur in 2 strings, you can use collections.Counter
guess = "RGOY "
solution = "RGYB"
a = collections.Counter(guess)
b = collections.Counter(solution)
a & b
Counter({'G': 1, 'R': 1, 'Y': 1})
correct_colours = sum((a & b).values())
3
So the user guessed 3 colours correctly
Correct locations
can be solved with an easy list comprehension
[g == s for g, s in zip(guess, solution)]
[True, True, False, False]
sum(g == s for g, s in zip(guess, solution))
2
so the used put 2 colours on the correct location
This is a MasterMind I made in Python. Hope you like it and it helped you! :)
import random
import time
from tkinter import *
def select_level():
global level
level = level_selector.get()
root.destroy()
root = Tk()
level_selector = Scale(root, from_=1, to=3, tickinterval=1)
level_selector.set(0)
level_selector.pack()
Button(root, text="Select a difficulty level", command=select_level).pack()
mainloop()
cpc_1_digit = 0
cpc_2_digit = 0
cpc_3_digit = 0
cpc_4_digit = 0
p_1_digit = 0
p_2_digit = 0
p_3_digit = 0
p_4_digit = 0
correct_correct = 0
correct_wrong = 0
chances = 0
if level == 1:
chances = 15
elif level == 2:
chances = 10
else:
chances = 7
cpc_1_digit = random.randint(0, 9)
while cpc_2_digit == cpc_1_digit or cpc_2_digit == cpc_3_digit or cpc_2_digit ==
cpc_4_digit:
cpc_2_digit = random.randint(0, 9)
while cpc_3_digit == cpc_1_digit or cpc_3_digit == cpc_2_digit or cpc_3_digit ==
cpc_4_digit:
cpc_3_digit = random.randint(0, 9)
while cpc_4_digit == cpc_1_digit or cpc_4_digit == cpc_2_digit or cpc_4_digit ==
cpc_3_digit:
cpc_4_digit = random.randint(0, 9)
while chances > 0:
correct_correct = 0
correct_wrong = 0
answer = input("Enter a four-digit number with different digits (e.g 1476): ")
p_1_digit = int(answer[0])
p_2_digit = int(answer[1])
p_3_digit = int(answer[2])
p_4_digit = int(answer[3])
if p_1_digit == cpc_1_digit:
correct_correct = int(correct_correct) + 1
elif p_1_digit == cpc_2_digit or p_1_digit == cpc_3_digit or p_1_digit ==
cpc_4_digit:
correct_wrong = int(correct_wrong) + 1
else:
pass
if p_2_digit == cpc_2_digit:
correct_correct = correct_correct + 1
elif p_2_digit == cpc_1_digit or p_2_digit == cpc_3_digit or p_2_digit ==
cpc_4_digit:
correct_wrong = int(correct_wrong) + 1
else:
pass
if p_3_digit == cpc_3_digit:
correct_correct = int(correct_correct) + 1
elif p_3_digit == cpc_1_digit or p_3_digit == cpc_2_digit or p_3_digit ==
cpc_4_digit:
correct_wrong = int(correct_wrong) + 1
else:
pass
if p_4_digit == cpc_4_digit:
correct_correct = int(correct_correct) + 1
elif p_4_digit == cpc_1_digit or p_4_digit == cpc_3_digit or p_4_digit ==
cpc_2_digit:
correct_wrong = int(correct_wrong) + 1
else:
pass
print("")
if int(correct_correct) == 4:
print("Congratsulations! You found the computer's number!")
break
elif int(correct_wrong) > 0 or int(correct_correct) >= 1 and int(correct_correct)
< 4:
print("You got " + str(correct_correct) + " correct digit(s) in the correct
place, and " + str(correct_wrong) + " correct digit(s) but in wrong place.")
elif int(correct_correct) == 0 and int(correct_wrong) == 0:
print("You didn't guess any number, try again!")
else:
raise Exception("CheckError: line 69, something went wrong with the
comparings.")
exit()
print("")
chances = chances - 1
if chances == 0:
print("You lost... The secret number was " + str(cpc_1_digit) + str(cpc_2_digit)
+ str(cpc_3_digit) + str(cpc_4_digit) + ". Try again by rerunning the program.")
time.sleep(4)

Issue setting matplot points color and shape

Whenever I run the display_data function (when there is data to be run after successfully answering at least one calculation_game question) I get an error that says:
"ValueError: to_rgba: Invalid rgba arg "o"
to_rgb: Invalid rgb arg "o"
could not convert string to float: 'o'"
When I run the code without the "o" to define the shape of the points it works fine and displays blue points. Only thing is that I want to be able to define shapes such as "o" and "v" because the plot will be showing data from multiple list when it is done. Any ideas?
NOTE:
There are missing functions below. I removed them here because they are not needed for the question.
import random
from random import randint
import time
import math
import matplotlib.pyplot as plt
# Number of problems for each practice/real round
practice_round = 0
real_round = 3
main_record = []
CALC_RECORD = []
# (1) Calculation Game ---------------------------------------------------------
'''Calculation game is a math game'''
def calculation():
response_time = None
# Determine the min and max calculation values
min_calculation_value = 1
max_calculation_value = 10
# Generate the problems
print('\nSolve the following problem:')
a = random.randint(min_calculation_value, max_calculation_value)
b = random.randint(min_calculation_value, max_calculation_value)
problem_type = random.randint(1,2)
if problem_type == 1:
answer = a * b
print(a, '*', b)
elif problem_type == 2:
answer = a % b
print(a, '%', b)
# Get the user's answer determine what to do if correct
start_time = time.time()
user_answer = input('\nEnter your answer: ')
end_time = time.time()
if user_answer == str(answer):
response_time = end_time - start_time
print('You are correct!')
elif user_answer != str(answer):
print('Oops, you are incorrect.')
# Return game id, start time, and response time
return("calculation", start_time, response_time)
def calculation_game():
record = []
# Generate two problems for a practice round
print("\nLet's begin with 2 practice problems.")
for i in range (practice_round):
print('\nPractice Problem', i + 1, 'of', practice_round)
calculation()
# Generate 10 problems for a real, recorded round
print("\nNow let's try it for real this time.")
for i in range (real_round):
print('\nProblem', i + 1, 'of', real_round)
# Append records for each iteration
record.append(calculation())
main_record.extend(record)
CALC_RECORD.extend(record)
return record
# (5) Display Data -------------------------------------------------------------
def display_data():
plt.ylabel('Time Per Question')
plt.xlabel('Round Played')
CALC_RECORD.sort(key=lambda record:record[1])
calc_time = [t[2] for t in CALC_RECORD if t[0] =='calculation' and t[2] != None]
alist=[i for i in range (len(calc_time))]
if len(calc_time) >0:
print (calc_time)
x = alist
y = calc_time
plt.scatter(x, y, c="bo")
plt.show(block=True)
main_menu()
# (6) Save Progress ------------------------------------------------------------
# (7) Load Data ----------------------------------------------------------------
# (8) Quit Game ----------------------------------------------------------------
def quit_game():
print('\nThank you for playing!')
# Main Menu --------------------------------------------------------------------
def menu():
print("\nEnter 1 to play 'Calculation'")
print("Enter 2 to play 'Binary Reader'")
print("Enter 3 to play 'Trifacto'")
print("Enter 4 to view your statistics")
print("Enter 5 to display data")
print("Enter 6 to save your progress")
print("Enter 7 to load data")
print("Enter 8 to quit the game")
def main_menu():
print('Welcome!')
user_input = ''
while user_input != '8':
menu()
user_input = input('\nWhat would you like to do? ')
if user_input == '1':
calculation_game()
if user_input == '2':
binary_reader_game()
if user_input == '3':
trifacto_game()
if user_input == '4':
display_statistics()
if user_input == '5':
display_data()
if user_input == '8':
quit_game()
main_menu()
Got it, just had to remove the c= part from plt.scatter(x, y, c="bo")

Categories

Resources