FINISHED LAB 11

This commit is contained in:
RustyRaptor committed 2019-12-05 13:53:07 -07:00
1 parent 4d63e2891d
commit 586dc7dd90
3 files changed
+90 -21

No files matched your search

+22 -21
View File
@@ -1,23 +1,24 @@
in_data = input("Please enter 4-digit code: ")
while True:
data_list = [char for char in in_data]
first_digit = 0
second_digit = 0
in_guess = input("Please enter a guess or 0 to stop")
if in_guess == "0":
break
guess_list = [char for char in in_guess]
score1 = 0
for key, val in enumerate(guess_list):
if guess_list[key] == data_list[key]:
guess_list[key] = 0
data_list[key] = 0
score1+=10
for key, val in enumerate(guess_list):
for idx, i in enumerate(data_list):
if i == guess_list[key] and guess_list[key] != 0 and i != 0:
score1+=1
guess_list[key] = 0
data_list[idx] = 0
print("Score: ", score1)
data_list = [char for char in in_data]
first_digit = 0
second_digit = 0
in_guess = input("Please enter a guess or 0 to stop")
if in_guess == "0":
break
guess_list = [char for char in in_guess]
score1 = 0
for key, val in enumerate(guess_list):
if guess_list[key] == data_list[key]:
guess_list[key] = 0
data_list[key] = 0
score1 += 10
for key, val in enumerate(guess_list):
for idx, i in enumerate(data_list):
if i == guess_list[key] and guess_list[key] != 0 and i != 0:
score1 += 1
guess_list[key] = 0
data_list[idx] = 0
print("Score: ", score1)
+11
View File
@@ -0,0 +1,11 @@
# CS 278 Lab 11
Done in python3
## How to Run on CS Machines
```
cd <source folder>
python3 lab11.py
```
+57
View File
@@ -0,0 +1,57 @@
import itertools
def convert_tuple(tup):
new_list = []
for i in tup:
new_list.append(str(i))
new_string = ''.join(new_list)
return new_string
def refer(code, guess):
data_list = [char for char in code]
guess_list = [char for char in guess]
score1 = 0
for key2, val2 in enumerate(guess_list):
if guess_list[key2] == data_list[key2]:
guess_list[key2] = 0
data_list[key2] = 0
score1 += 10
for key2, val2 in enumerate(guess_list):
for idx, i in enumerate(data_list):
if i == guess_list[key2] and guess_list[key2] != 0 and i != 0:
score1 += 1
guess_list[key2] = 0
data_list[idx] = 0
return score1
nums = list(range(1, 7))
sequences = [x for x in itertools.product(nums, repeat=4)]
possible = [True] * len(sequences)
start = 0
turns = 0
print("Please think of a 4 digit code with numbers between 1 and 6 and let me "
"guess it.")
while True:
print("There are", possible.count(True), "possible guesses. I am "
"guessing",
convert_tuple(sequences[start]))
turns += 1
score = int(input("Please enter the score"))
if score == 40:
print("Found in ", turns, "Turns")
print("Thank you for playing with me!")
break
else:
possible[start] = False
for key, val in enumerate(sequences):
if refer(convert_tuple(sequences[start]), convert_tuple(val)) != score:
possible[key] = False
if possible.count(True) == 0:
print("No more possibilities, please try again")
break
start = possible.index(True)