Created
May 8, 2018 08:11
-
-
Save ErikThorsell/a46bf190d692033f60f61809cf5117ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.6 | |
# -*- coding: utf-8 -*- | |
# | |
# Imports | |
# | |
from random import randint | |
############################################################################### | |
# MAIN # | |
############################################################################### | |
def main(): | |
print("Den som först kommer till noll (0) vinner. Vi börjar på 20, du får subtrahera ett till tre (1-3).") | |
print("Lycka till!") | |
rem = 20 | |
turn = None | |
print("Vem börjar?") | |
turn = input("Datorn (d) eller spelare (s)? d/s: ") | |
while True: | |
print("") | |
if turn == "d": | |
e = randint(1, 3) | |
print(f"Datorn subtraherar {e}") | |
else: | |
e = int(input("Ge ett tal mellan ett och tre (1-3): ")) | |
if not 1 <= e <= 3: | |
print("Ottillåten inmatning!") | |
continue | |
rem -= e | |
print(f"Återstående värde: {rem}") | |
if rem <= 0: | |
print(f"{turn} vann!") | |
break | |
if turn == "d": | |
turn = "s" | |
else: | |
turn = "d" | |
############################################################################### | |
# RUN # | |
############################################################################### | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment