Skip to content

Commit 8c57555

Browse files
authored
Add files via upload
1 parent a8bf25f commit 8c57555

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

crypto.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import requests
2+
3+
cryptocurrency = input("Enter The Crypto Currency Name : ").lower()
4+
5+
url = f"https://api.coingecko.com/api/v3/coins/{cryptocurrency}"
6+
7+
response = requests.get(url)
8+
9+
if response.status_code == 200:
10+
data = response.json()
11+
print(f"Details for {cryptocurrency.upper()}:")
12+
print("Name:", data['name'])
13+
print("Symbol:", data['symbol'])
14+
print("Current Price (₹):", data['market_data']['current_price']['inr'])
15+
16+
else:
17+
print(f"Failed to fetch data for {cryptocurrency}. Status code:", response.status_code)

rockpaperscissor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# W A P to play rock paper scissor
2+
3+
import random
4+
5+
options = ("rock", "paper", "scissors")
6+
running = True
7+
8+
while running:
9+
10+
player = None
11+
computer = random.choice(options)
12+
13+
while player not in options:
14+
player = input("Enter a choice (rock, paper, scissors): ")
15+
16+
print("Player: ", player)
17+
print("Computer: ", computer)
18+
19+
if player == computer:
20+
print("It's a tie!")
21+
elif player == "rock" and computer == "scissors":
22+
print("You win!")
23+
elif player == "paper" and computer == "rock":
24+
print("You win!")
25+
elif player == "scissors" and computer == "paper":
26+
print("You win!")
27+
else:
28+
print("You lose!")
29+
30+
if not input("Play again? (y/n): ").lower() == "y":
31+
running = False
32+
33+
print("Thanks for playing!")

tictactoe.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# W A P to play tic tac toe
2+
3+
import random
4+
5+
def sum(a, b, c):
6+
return a + b + c
7+
8+
def printBoard(xState, zState):
9+
zero = 'X' if xState[0] else ('O' if zState[0] else 0)
10+
one = 'X' if xState[1] else ('O' if zState[1] else 1)
11+
two = 'X' if xState[2] else ('O' if zState[2] else 2)
12+
three = 'X' if xState[3] else ('O' if zState[3] else 3)
13+
four = 'X' if xState[4] else ('O' if zState[4] else 4)
14+
five = 'X' if xState[5] else ('O' if zState[5] else 5)
15+
six = 'X' if xState[6] else ('O' if zState[6] else 6)
16+
seven = 'X' if xState[7] else ('O' if zState[7] else 7)
17+
eight = 'X' if xState[8] else ('O' if zState[8] else 8)
18+
19+
print("-------------")
20+
print(f"| {zero} | {one} | {two} |")
21+
print("|---|---|---|")
22+
print(f"| {three} | {four} | {five} |")
23+
print("|---|---|---|")
24+
print(f"| {six} | {seven} | {eight} |")
25+
print("-------------")
26+
27+
def checkWin(xState, zState):
28+
wins = [
29+
[0, 1, 2], [3, 4, 5], [6, 7, 8],
30+
[0, 3, 6], [1, 4, 7], [2, 5, 8],
31+
[0, 4, 8], [2, 4, 6]
32+
]
33+
for win in wins:
34+
if sum(xState[win[0]], xState[win[1]], xState[win[2]]) == 3:
35+
print("\nX Won the match")
36+
return 1
37+
if sum(zState[win[0]], zState[win[1]], zState[win[2]]) == 3:
38+
print("\nO Won the match")
39+
return 0
40+
return -1
41+
42+
def computerMove(zState, xState):
43+
empty_cells = [i for i in range(9) if not (xState[i] or zState[i])]
44+
return random.choice(empty_cells)
45+
46+
if __name__ == "__main__":
47+
xState = [0, 0, 0, 0, 0, 0, 0, 0, 0]
48+
zState = [0, 0, 0, 0, 0, 0, 0, 0, 0]
49+
turn = 1
50+
print("Welcome to Tic Tac Toe\n")
51+
while True:
52+
printBoard(xState, zState)
53+
54+
if turn == 1:
55+
print("\nX's Chance")
56+
value = int(input("Please enter a value: "))
57+
xState[value] = 1
58+
else:
59+
print("\nO's Chance (Computer)")
60+
value = computerMove(zState, xState)
61+
zState[value] = 1
62+
print(f"Computer's choice: {value}\n")
63+
64+
cwin = checkWin(xState, zState)
65+
if cwin != -1:
66+
print("\nMatch over")
67+
break
68+
69+
turn = 1 - turn

weatherapi.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import datetime as dt
2+
import requests
3+
4+
base_url = "https://api.openweathermap.org/data/2.5/weather?"
5+
api_key = "412c6fc197bba66aadf429e7e1a835f2"
6+
city = input("Enter City Name: ")
7+
8+
def kel_to_cel_fahren(kelvin):
9+
celsius = kelvin - 273
10+
fahrenheit = celsius * (9/5) + 32
11+
return celsius, fahrenheit
12+
13+
url = base_url + 'appid=' + api_key + '&q=' + city
14+
response=requests.get(url).json()
15+
16+
temp_kelvin=response['main']['temp']
17+
temp_celsius, temp_fahrenheit=kel_to_cel_fahren(temp_kelvin)
18+
max_temp=response['main']['temp_max']
19+
tempc,tempf=kel_to_cel_fahren(max_temp)
20+
min_temp=response['main']['temp_min']
21+
temc,temf=kel_to_cel_fahren(min_temp)
22+
humidity=response['main']['humidity']
23+
description=response['weather'][0]['description']
24+
sunrise=dt.datetime.utcfromtimestamp(response['sys']['sunrise']+response['timezone'])
25+
sunset=dt.datetime.utcfromtimestamp(response['sys']['sunset']+response['timezone'])
26+
27+
print(f"\nWeather Details For {city}")
28+
print(f"\nTempertature: {temp_celsius:.2f}'C or {temp_fahrenheit}'F")
29+
print(f"Maximum Tempertature: {tempc:.2f}'C or {tempf}'F")
30+
print(f"Minimum Tempertature: {temc:.2f}'C or {temf}'F")
31+
print(f"Humidity in {city}: {humidity}%")
32+
print(f"General Weather in {city}: {description}")
33+
print(f"Sunrises in {city} at {sunrise}.")
34+
print(f"Sunsets in {city} at {sunset}.\n")
35+

0 commit comments

Comments
 (0)