Day 047 - Project 47 : Top Trumps

If you have any questions, comments or issues with this project please post them here!

since this isn’t in the solution and nobody has posted here yet, i decided to post my attempt that includes the option to add more cards. it works, but is probably much more convoluted than necessary. my decision to add an ā€œidā€ key probably didn’t help much either, but that’s what i came up with at the time.

import random,os,time

Trumps={  
  "Admiral Halsey":{"Verbality":70,"Calculussity":31,"Shaperotaterness":17,"id":1},
  "Vice Admiral Beatty":{"Verbality":45,"Calculussity":31,"Shaperotaterness":18,"id":2}
}

def Cardid(i):
  for key, value in Trumps.items():
    if Trumps[key]["id"]==i:
      return key,Trumps[key]

def ran(i):
  num=random.randint(1,len(Trumps))
  while num==i:
    num=random.randint(1,len(Trumps))
  return num
    
def battle(AllStats1,AllStats2,Stat1):
  if AllStats1[1][Stat1]>AllStats2[1][Stat1]:
    print(f"\n{AllStats1[0]}'s {Stat1} of {AllStats1[1][Stat1]} beats {AllStats2[0]}'s {Stat1} of {AllStats2[1][Stat1]}!")
  elif AllStats1[1][Stat1]<AllStats2[1][Stat1]:
    print(f"\n{AllStats1[0]}'s {Stat1} of {AllStats1[1][Stat1]} loses to {AllStats2[0]}'s {Stat1} of {AllStats2[1][Stat1]}!")
  else:
    print("\nIt's a draw!")
  cont=input("\nContinue y/n? > ").strip().lower()
  if cont[0]=="y":
    os.system("clear")
    return
  else:
    exit()

def AddCard():
  name=input("\nName your card > ")
  verb=int(input("Enter a Verbality score > "))
  calc=int(input("Enter a Calculussity score > "))
  shape=int(input("Enter a Shaperotaterness score > "))
  id=len(list(Trumps))+1

  Trumps[name]={"Verbality":verb,"Calculussity":calc,"Shaperotaterness":shape,"id":id}
  print(f"\n{name} has been added.")
  time.sleep(2)
  os.system("clear")
  return

while True:
  print("=Random Character Battle=\nChoose or add your character > \n")
  print("0 - add character")
  for key,value in Trumps.items():
    print(f"{Trumps[key]['id']} - {key}")

  Card1=int(input("> "))
  if Card1==0:
    AddCard()
  else:
    Card2=ran(Card1)
  
    AllStats1={}
    AllStats2={}  
    AllStats1=Cardid(Card1)
    AllStats2=Cardid(Card2)
    
    print("\nChoose your stat:\n")
    Stat1=int(input("1 - Verbality\n2 - Calculussity\n3 - Shaperotaterness\n > "))
    if Stat1==1:
      Stat1="Verbality"
    elif Stat1==2:
      Stat1="Calculussity"
    elif Stat1==3:
      Stat1="Shaperotaterness"      
    
    battle(AllStats1,AllStats2,Stat1)

comments appreciated!

It’s hard to recognize it from the code :rofl: but it seems i’m really into random :upside_down_face: !

# -*- coding: utf-8 -*-
"""
Created on Thu Feb  2 15:50:14 2023

@author: soreen
"""
import random, time

trumps = {}

def numR():
    for i in range(100):
        num = random.randint(1,100)
        return num

def coloR():
    col = ['\033[35m','\033[34m','\033[32m','\033[33m','\033[31m','\033[1m']
    colR = random.choice(col)
    return colR
    
trumps["Allah"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Jesus"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Budha"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Hera"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Zeus"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Trump"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Putin"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}
trumps["Xi"] = {"Intelligence": numR(), "Speed": numR(), "HP": numR(), "Weight": numR()}

print()

start_string = "Let's GO!\n\n"

while True:
#    for i in start_string.upper():
#        print(i, end="")
    print("And the fighters are: \n\n")    
    for key in trumps:
        print(coloR(),key)
    user = input("\033[0m\nChoose your fighter: ").capitalize()
    
    comp = random.choice(list(trumps.keys()))
    print("\nYour computer is choosing hero: ")
    for i in range(20):
        print(".", end="")
        time.sleep(0.15)
    time.sleep(0.2)
    print(f"\nYour computer has picked {coloR()}{comp}\033[0m! šŸ‘¹ ...")
    print()
    for i in start_string.upper():
        print(i, end="")
    
    print("Choose stats to compare: Intelligence, Speed, HP or Weight")
    answer = input("\n> ").capitalize()
    
    print(f"{user}: {trumps[user][answer]}")
    print(f"{comp}: {trumps[comp][answer]}")
    
    if trumps[user][answer] > trumps[comp][answer]:
        print(f"{coloR()}{user} \033[0mWins")
    elif trumps[user][answer] < trumps[comp][answer]:
        print(f"{coloR()}{comp} \033[0mWins")
    else:
        print("It's a draw!")

Please note: i’m sort of TheGrandfather in coding (age=51) so i might be a bit politically incorrect! No dissent intended - it’s just for fun!

3 Likes

I really liked the made up stat names :)))

what is the meaning of the word TRUMP?

Hey @WaayeelkaCraxma welcome to the forums!

I think its the name of a game played in the UK.

1 Like

ā€˜Trump’ is a word used in card games when you win due to a better ranking card. That would be your ā€˜Trump Card’

Fun Fact:
In Germany there is a saying: ā€œHeart is Trump.ā€ It means, Heart beats all other cards, but it also applies to Real Life! :wink: