From 76ac306c96d3eb2fab1813df3c91e10f4af23570 Mon Sep 17 00:00:00 2001 From: Lucifer Date: Sat, 5 Sep 2026 20:12:39 +0530 Subject: [PATCH 1/2] UNO_game a side project in python where we create a working UNO game with every set of rules applicable in the real World UNO. --- UNO_game | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 UNO_game diff --git a/UNO_game b/UNO_game new file mode 100644 index 0000000..7fb78bb --- /dev/null +++ b/UNO_game @@ -0,0 +1,104 @@ +import random #used RANDOM so that har baar actual random shuffle ho +deck =[] +colors= ["red", "yellow", "green", "blue"] +for col in colors: + deck.append([col,0]) # 0th number ka card 1 hi baar hota hai so ek baar hi append + + for num in range(1,10): + deck.append([col,num]) #baqi har numbered card 2 baar hote hai, so do baar append + deck.append([col,num]) + +#till now, the length of deck should be 76 (numbered cards) + +actions =["skip", "reverse", "+2"] #action cards +for col in colors: + for act in actions: + deck.append([col,act]) # 2 baar, as har action card 2 hota hai + deck.append([col,act]) + +for i in range(4): + deck.append(["wild","color change"]) # har wild card 4 piece hota hai, so range 0 se 4 tk = 3 cards ka loop + deck.append(["wild", "+4"]) + +random.shuffle(deck) #to shuffle the deck after putting in all the cards + +print("\nThe deck of cards is :", deck) +print("\nThe length of deck is:", len(deck)) # 108 hona chahiye + +player=[] +computer=[] + +for i in range(7): # 0 se 6 tak draw hoga (as player and computer dono ko 7-7 cards) + player.append(deck.pop()) #player ki list me card daalo using pop() + computer.append(deck.pop()) #same for computer + +print("\nPlayer got the cards: ", player) #to display kaunsa mila +print("\ncomputer got the cards: " , computer) # same + +floor= [deck.pop()] #table pe jo card rehta hai (initially ek hi card..pop()use kiya with same logic) + +print("\nThe card on the table is:", floor) #table pe jo card pada hai usko show krne ko + +def allowed_play(card, floor): # ek function bnaya "allowed_play" naam se + color,value = card + f_color, f_value=floor[-1] # [-1] index pe jo card hai FLOOR list me, sirf usi ko consider krrhe , cuz waise bhi only that matters + + if color==f_color: #if hmare card ka color floor card se same.. then no issues + return True + elif value == f_value: #if value same , then no issues + return True + elif color == "wild": #if wild card khelna hai, then no issues + return True + else: + return False + +while True: #ek while loop which only runs if upr ki conditions are true + + print("\nAfter last move, the topmost played card on the table:", floor[-1]) #again, just to see floor (table pe) kaunsa card hai + print("\nThe cards you have:") + + for i in range(len(player)): + print(i ,":", player[i]) # mere har index value ke saath mere us index ka card print hojaega from my list named player" + + move = input("Please enter the card number to play, or D to draw a card: ") #initinally string type input rkha hai, cuz D bhi allow krrhe + + if move=="D": + player.append(deck.pop()) #if DRAW krna hai, toh player ki list me add krdo + print("\nYou drew a card from the deck, your updated player deck is: ", player) #updated list of player's card print krdo + break + + move=int(move) #then, move ko INT type banao.. so that indexing me use hoske... + chosen_card = player[move] # and then us index ka card player ki list se nikaal kr CHOSEN_CARD me daal do temporarily + + if allowed_play(chosen_card,floor): #if wo chosen card allowed_play fuction ko satisfy krrha.. + floor.append(chosen_card) # toh table pe phek do us card ko + player.pop(move) #player ke card list me se pop krdo usko + print("after playing the card, the updated player's deck :",player) + print("\nyou played the card:" , chosen_card) + break + else: + print("\nInvalid move, try again...") # if satisfy nhi krrha, invalid move + + if len(player)==0: # poore time, jaise hi length of player's list ZERO hogyi.. player game jeet jayega.. + print("YOU WON THE GAME... WOOHOOOO !!!") + break + +comp_played=False #just a temporary variable so that isko IFk saath use kr ske in line 99 +print("\nAfter player's move, The topmost card on the table is :", floor[-1]) +print("\nCOMPUTER'S CHANCE NOW...") +for card in computer: #traverse krne ke liye through the computer's deck + if allowed_play(card,floor): # if allowed_play function ko satisfy krrha hai toh... + print("\nthe available deck of computer is: ",computer) + floor.append(card) #[mtlb humne traverse kia through the computer's list and jo pehla card mila usko khel dia computer ne] + computer.remove(card) # computer deck se remove + print("\ncomputer played:", card) + print("\nafter it's move, the updated deck of computer is: ",computer) + print("\nthe latest card on the table is :", floor[-1]) + comp_played=True # mtlb computer ne kheldia to break krenge ab loop se... + break +if comp_played==False: #agr poori list me koi bhi card satisfy na kre toh + computer.append(deck.pop()) #ek card uthaega computer + print("\nComputer Drew a card from the deck: ",computer[-1] ) #just to see kaunsa card uthaya + + + From cb0f3fa690c1290eeefd7a2e5b252e8cbe06845f Mon Sep 17 00:00:00 2001 From: Lucifer Date: Sun, 6 Sep 2026 13:53:04 +0530 Subject: [PATCH 2/2] loops practice in python pattern printing in python to understand the working of loops better. --- loops practice in python | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 loops practice in python diff --git a/loops practice in python b/loops practice in python new file mode 100644 index 0000000..4603aca --- /dev/null +++ b/loops practice in python @@ -0,0 +1,74 @@ +# PATTERN 1: Simple Right-Angled Triangle (Stars) +# - Outer loop (i) controls the rows (1 to n). +# - Inner loop (j) controls the columns/stars in each row (1 to i). + + +print("Simple Star Triangle") +n = 5 + +for i in range(1, n + 1): # Row loop + for j in range(1, i + 1): # Column loop prints 'i' stars per row + print("*", end=" ") # end=" " prevents going to a new line + print() # Moves cursor to the next line after row ends + +print("\n" + "="*40 + "\n") + + + +# PATTERN 2: Inverted Right-Angled Triangle (Stars) +# - Row loop starts from max 'n' and goes down to 1 using step -1. +# - Inner loop prints stars matching the decreasing row number. + +print("Inverted Star Triangle") + +for i in range(n, 0, -1): # Rows go: 5, 4, 3, 2, 1 + for j in range(1, i + 1): # Prints stars equal to current row 'i' + print("*", end=" ") + print() + +print("\n" + "="*40 + "\n") + + +# PATTERN 3: Number Triangle (Row Number Pattern) +# - Instead of printing a fixed star (*), print the row number 'i'. +# - It repeats the current row number 'i' times. + +print("Number Triangle (Repeating Row)") + +for i in range(1, n + 1): # Row loop + for j in range(1, i + 1): # Column loop + print(i, end=" ") # Print row number instead of '*' + print() + +print("\n" + "="*40 + "\n") + + +# PATTERN 4: Centered Pyramid Star Pattern +# - We need two things per row: Leading spaces and Stars. +# - Spaces decrease as rows increase: (n - i) spaces. +# - Stars increase: 'i' stars separated by spaces. + +print("Centered Pyramid Star Pattern") + +for i in range(1, n + 1): + # Print spaces to center-align the triangle + print(" " * (n - i), end="") + # Print stars with a space after each star + print("* " * i) + +print("\n" + "="*40 + "\n") + + +# PATTERN 5: Floyd's Triangle (Continuous Numbers) +# - Keep a separate counter variable starting at 1. +# - Increment the counter continuously across rows without resetting. + +print("Floyd's Triangle (Consecutive Numbers)") + +current_number = 1 # Track continuous numbers + +for i in range(1, n + 1): + for j in range(1, i + 1): + print(current_number, end=" ") + current_number += 1 # Increment so numbers keep growing (1, 2, 3...) + print()