repl.it
@bradenrueter/

Doubt That Derivative!

Python

Hello everybody and welcome back to "Doubt That Derivative"! Today we have <contestants> very special contestants here live from <location>!

fork
loading
Files
  • main.py
  • Doubt-That-Derivative.zip
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import time, math, random, termcolor

def scrollText(color,scrollDelay,phrase):
  print(termcolor.colored(phrase,color))
  for d in range(0,1000):
    print("\n")
    time.sleep(scrollDelay)

players = {}
ground = 1 #Game round

def clear():
  print("\n" * 100)

clear()

while True:
  try:
    contestants = int(input(termcolor.colored("How many contestants do we have here today folks?","cyan")))
    clear()
    break
  except:
    input(termcolor.colored("Sorry, that's invalid!","red"))
    clear()

for i in range(1,contestants+1):
  players[str(i)] = [(input(termcolor.colored("What is contestant %s's name?" % (i),"green")),0),0]
  clear()
#What you go for
while(True):
  pointVsRound = input(termcolor.colored("Are we playing for points or rounds, folks?","cyan"))
  clear()
  if(pointVsRound.lower() == "rounds"):
    while(True):
      try:
        round_num = int(input(termcolor.colored("How many rounds are there to be played?","cyan")))
        check_for = "rounds"
        clear()
        break
      except:
        print(termcolor.colored("The input should be a number.","red"))
        time.sleep(2)
        clear()
    break
  elif(pointVsRound.lower() == "points"):
    while(True):
      try:
        point_num = int(input(termcolor.colored("How many points are we playing to, today?","cyan")))
        check_for = "points"
        clear()
        break
      except:
        print(termcolor.colored("The answer must be a number.","red"))
        time.sleep(2)
        clear()
    break
  else:
    print(termcolor.colored("That is not an option.  The options are points or rounds.","red"))
    time.sleep(2)
    clear()
#Timing, generation, and calculation sequence
while True:
  clear()
  print(termcolor.colored("Welcome to round %s!\n" % (ground),"green"))
  time.sleep(1)
  for a in range(1,contestants + 1):
    print(termcolor.colored("Here we have contestant %s!\n" % (a),"yellow"))
    time.sleep(1)
    start = time.time()
    
    num1 = random.randint(1,20)
    num2 = random.randint(1,6)
    
    derivative = (str(num1) + "x^" + str(num2))
    contestant_answer = input(termcolor.colored("What is the derivative of " + derivative + "?","blue"))
    
    timetaken = round(time.time() - start,3)
    if(num2 != 1):
      answer = (str(num1 * num2) + "x^" + str(num2 - 1))
    else:
      answer = (str(num2 * num1))
    
    if contestant_answer == answer:
      print(termcolor.colored("\nGood job! You solved the problem in %s seconds!\n" % (timetaken),"green"))
      players[str(a)][1] += 1
    else:
      print(termcolor.colored("\nYou got the answer wrong.\n","red"))
    time.sleep(1)
    print(termcolor.colored("You currently have %s points contestant %s!\n" % (players[str(a)][1],a),"blue"))
    time.sleep(1)
  ground += 1
#checking the scores and rounds
  if(check_for == "rounds"):
    if(ground == round_num + 1):
      greatest_score = 0
      for c in range(1,contestants+1):
        if(players[str(c)][1] == greatest_score):
           

        if(players[str(c)][1] > greatest_score):
          greatest_score = players[str(c)][1]
          greatest_score_owner = players[str(c)][0][0]
      print(termcolor.colored("The winner is " + str(greatest_score_owner) + " with " + str(greatest_score) + " points!","yellow"))
      break
  elif(check_for == 'points'):
    for b in range(1, contestants+1):
      if(players[str(b)][1] == point_num):
        winner = players[str(b)][0][0]
        print(termcolor.colored(winner + " has won the game!","yellow"))
        b = contestants + 1
        break
?