Skip to content

Instantly share code, notes, and snippets.

@jonaslsaa
Created December 3, 2014 11:33
Show Gist options
  • Save jonaslsaa/523c08278d0c5a5cf05e to your computer and use it in GitHub Desktop.
Save jonaslsaa/523c08278d0c5a5cf05e to your computer and use it in GitHub Desktop.
The Smart Test! Using DBs. Original by Mikkel
print('Welcome to Smart Test!')
print("Made by VOX.")
print("Adapted from Downy Test created Mikkel helped by VOX.")
print("\n"*3)
print("Loading...")
import time
import os
import random
try:
file_read = open("DB.txt", "r")
except IOError:
print("Something wrong happened while trying to read database.")
print("\n")
try:
file_write = open("DB.txt", "a")
print("LOADED DATABASE!")
except IOError:
print("Something wrong happened while trying to write to database.")
wait_time = 1
name = raw_input("Your name: ")
time.sleep(wait_time)
rnd = random.randint(0, 100)
new_smart = rnd
hasName = False
canExecute = False
num_lines = sum(1 for line in open('DB.txt'))
count_line = 1
for current_line in file_read:
current_name = ''.join([i for i in current_line if not i.isdigit()])
current_smart = ''.join([i for i in current_line if i.isdigit()])
#print(current_line + "," + current_name + "," + current_smart + "," + name.lower()) # for debug!
#print(str(count_line)+" "+str(num_lines))
if name.lower() == current_name.strip():
smart = current_smart
print(name + " is " + smart + "% smart!")
break
elif name.lower() != current_name.strip() and canExecute == True:
file_write.write("\n" + name.lower() + " " + str(new_smart))
print(name + " is " + str(new_smart) + "% smart!")
break
else:
count_line += 1
if count_line == num_lines:
canExecute = True
file_write.close()
file_read.close()
dummie = raw_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment