html cgi

jenny2000000
guesscard.cgi
#! /usr/bin/env python import cgi print('Content-type: text/html\n') html = """

You guessed:

Suit:

{suit}

Rank:

{rank}
{again} """ form = cgi.FieldStorage() suit_guess = form.getfirst('suit', 'D') rank_guess = form.getfirst('rank', '2') our_guess = "10S" rank_dict = {"2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":10, "J":11, "Q":12, "K":13} if suit_guess == "S": suit_reply = "Correct Suit!" else: suit_reply = "Wrong Suit!" if rank_dict[rank_guess] < rank_dict["10"]: rank_reply = "Too Low!" if rank_dict[rank_guess] > rank_dict["10"]: rank_reply = "Too High!" if rank_dict[rank_guess] == rank_dict["10"]: rank_reply = "Correct Rank!" if suit_reply == "Correct Suit!" and rank_reply == "Correct Rank!": new_game = "Nice Job!" else: new_game = """

Try to guess the card!

Rank: 2 3 4 5 6 7 8 9 10 J Q K A

Suit: Clubs Diamonds Hearts Spades

Submit Reset """ image_fill = "cards/" +rank_guess + suit_guess +".jpg" print(html.format(image = image_fill, suit = suit_reply, rank = rank_reply, again = new_game))