Python Daily Evening (Jun 14th)
Scratchpad #1
# The line below print the result
# print(10 + 4 * 5) # this is the print function
# 100 + 5 # this is not going to print
# This code is going to hack
# print(into SBI)
# print(10000 / 2)
1000
print(1000)
score1 = 100
score2 = 75
score3 = 100 // 6
print(score1, score2, score3)
a = 10
b = 20
print(a + b)
Scratchpad #2
score = None
score = 10
Scratchpad #3
# name = "John Doe"
# print(name.lower().find("doe"))
# print(name.lower().find("doe") + 10)
# # 5
# ----------------
# print("Amount of US Dollars you want to convert?")
# usd = input("Amount of US Dollars you want to convert? ") # "100"
# # print(type(usd))
# inr = float(usd) * 75
# print(f"{usd} USD is equal to {inr} INR")
# x = 0
# if True:
# print("Hello Zero")
# # if 1:
# # print("Hello One")
# --------------
age = 35
if age >= 18:
print("You can enter but you can't drink.")
if age >= 21:
print("You are allowed to enter and drink")
if age >= 65:
print("Drink are free")
else:
print("You cannot enter")
Scratchpad #4
# print("Hello World!")
# # This is the print function
# print(100 * 2)
# print(100 - 50) # subtraction
# name = "john doe"
# num1 = 100
# num2 = 50
# print(name)
# print(num1 + num2)
# print("What is your name?")
# name = input("What is your name? ")
# print(f"Hello, {name}. How are you doing?")
# usd = input("Amount of US Dollars you want to convert? ")
# inr = float(usd) * 75
# print(f"{usd} USD is equal to {inr} INR")
# age = 35
# if age >= 18:
# print("You can enter but you can't drink.")
# if age >= 21:
# print("You are allowed to enter and drink")
# if age >= 65:
# print("Drink are free")
# else:
# print("You cannot enter")
a = 0
a = "Nasd"
res = a + 10
Scratchpad #5
# age = int(input("Please enter your age: "))
# age = int(age)
# if age >= 18 and age < 21:
# print("You can enter but you can't drink.")
# elif age >= 21 and age < 65:
# print("You are allowed to enter and drink")
# elif age >= 65:
# print("Drink are free")
# else:
# print("You cannot enter")
# age = int(input("Please enter your age: "))
# if age >= 18:
# if age >= 65:
# print("Drink are free")
# elif age >= 21:
# print("You are allowed to enter and drink")
# else:
# print("You can enter but you can't drink.")
# else:
# print("You cannot enter")
# ----------------
# print("...ROCK...")
# print("...PAPER...")
# print("...SCISSOR...\n")
# player1 = input("Please enter player 1's choice: ")
# player2 = input("Please enter player 2's choice: ")
# if player1 == player2:
# print("It's a tie")
# elif (
# (player1 == "rock" and player2 == "scissors")
# or (player1 == "paper" and player2 == "rock")
# or (player1 == "scissors" and player2 == "paper")
# ):
# print("Player 1 wins")
# elif (
# (player2 == "rock" and player1 == "scissors")
# or (player2 == "paper" and player1 == "rock")
# or (player2 == "scissors" and player1 == "paper")
# ):
# print("Player 2 wins")
# else:
# print("Something went wrong")
# for num in range(1, 21):
# if num == 5 or num == 16:
# print(f"{num} FizzBuzz")
# elif num % 2 == 0:
# print(f"{num} - Fizz is even")
# else:
# print(f"{num} - Fizz is odd")
# secret_password = input("Enter password: ")
# while secret_password != "balony1":
# # print("Incorrect password")
# secret_password = input("Incorrect! Enter password again: ")
for num in range(1, 11):
print(num)
num = 1
while num < 11:
print(num)
num += 1
Scratchpad #6
# for num in range(1, 11):
# print(num)
# num = 1
# while num < 11:
# print(num)
# num += 1
# secret_password = input("Enter password: ")
# count = 0
# while secret_password != "balony1":
# if count < 3:
# secret_password = input("Incorrect! Enter password again: ")
# if secret_password == "exit":
# break
# count += 1
# else:
# print("Try again later")
# break
# print("...ROCK...")
# print("...PAPER...")
# print("...SCISSOR...\n")
# player1 = input("Please enter player 1's choice: ")
# player2 = input("Please enter player 2's choice: ")
# if player1 == player2:
# print("It's a tie")
# elif (
# (player1 == "rock" and player2 == "scissors")
# or (player1 == "paper" and player2 == "rock")
# or (player1 == "scissors" and player2 == "paper")
# ):
# print("Player 1 wins")
# elif (
# (player2 == "rock" and player1 == "scissors")
# or (player2 == "paper" and player1 == "rock")
# or (player2 == "scissors" and player1 == "paper")
# ):
# print("Player 2 wins")
# else:
# print("Something went wrong")
# player1_score = 0
# player2_score = 0
# while True:
# print("Inside the loop")
# quit = input("Do you want to quit? ")
# if quit.lower() == "y" or quit.lower() == "yes":
# break
# print(f"Player 1 score: ")
# task1 = "buy milk"
# task2 = "pay bills"
# task3 = "clean up your room"
# tasks = "buy milk,pay bills,clean up your room"
# tasks = ["buy milk", "pay bills", "clean up your room"]
# numbers = [1, 2, 3, 4]
# i = 0
# while i < len(numbers):
# print(numbers[i] ** 2)
# i += 1
# tasks = ["buy milk", "pay bills", "clean up your room"]
# for task in tasks:
# print(task)
count = 0
while True:
break
# print(f"{count} - Inside the loop")
# count += 1
# if count > 100:
# break
Scratchpad #7
# nums = [1, 2, 3, 4, 5]
# # using a for loop
# nums2 = []
# for num in nums:
# if num % 2 == 0:
# nums2.append(num * num)
# print(nums2) # [1,4,9,16,25]
# # using comprehensions
# nums3 = [n * n for n in nums if n % 2 == 1]
# print(nums3)
# # using comprehensions
# nums3 = [n * n for n in nums if n % 2 == 1]
# print(nums3)
# # # using comprehensions
# # nums3 = [n * n * n for n in nums]
# # print(nums3)
# names = ["john", "jim", "jack", "brad", "leo"]
# uppercased = [name.upper() for name in names if name[0] == "b"]
# print(uppercased)
# # uppercased = []
# # for name in names:
# # if name[0] == "b":
# # uppercased.append(name.upper())
# # print(uppercased)
# nums = [1, 2, 3, 4, 5]
# # using a for loop
# nums2 = []
# for num in nums:
# if num % 2 == 0:
# nums2.append(num * 2)
# else:
# nums2.append(num / 2)
# print(nums2)
# # using comprehensions
# nums3 = [num * 2 if num % 2 == 0 else num / 2 for num in nums]
# print(nums3)
# nested_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# for li in nested_list:
# for item in li:
# print(item)
# [4, 5, 6]
# 1
# 2
# 3
# 4
# 5
# 6
age = 2
if age > 5:
if age > 20:
print("Above 20")
else:
print("Above 5")
else:
print("Something else")
Scratchpad #8
# # using comprehensions
# nums3 = [n * n * n for n in nums]
# print(nums3)
# names = ["john", "jim", "jack", "brad", "leo"]
# uppercased = [name.upper() for name in names if name[0] == "b"]
# print(uppercased)
# # using comprehensions
# nums3 = [num * 2 if num % 2 == 0 else num / 2 for num in nums]
# print(nums3)
# board = []
# for times in range(3):
# single = []
# for time in range(3):
# single.append(time)
# board.append(single)
# print(board)
# board = [["X" if num % 2 != 0 else "O" for num in range(1, 4)] for val in range(1, 4)]
# print(board)
# products = [
# [
# "Apple iPhone 13",
# "https://s3.aws.com/asdasd/asdasd.png",
# "Some description",
# 999.99,
# "Long Description",
# 123124,
# 100,
# ],
# [
# "One Plus",
# "https://s3.aws.com/asdasd/asdasd.png",
# "Some description",
# 499.99,
# "Long Description",
# 123124,
# 99,
# ],
# [
# "https://s3.aws.com/asdasd/asdasd.png",
# "Some description",
# 499.99,
# "One Plus",
# "Long Description",
# 99,
# 123124,
# ],
# {
# "name": "One Plus",
# "url": "https://s3.aws.com/asdasd/asdasd.png",
# "short_desc": "Some description",
# "price": 499.99,
# "long_desc": "Long Description",
# "inv": 99,
# "sku": 123124,
# },
# {
# "url": "https://s3.aws.com/asdasd/asdasd.png",
# "short_desc": "Some description",
# "price": 999.99,
# "name": "Apple iPhone",
# "long_desc": "Long Description",
# "inv": 99,
# "sku": 123124,
# },
# ]
# product = {
# "url": "https://s3.aws.com/asdasd/asdasd.png",
# "short_desc": "Some description",
# "long_desc": "Long Description",
# "price": 999.99,
# "name": "Apple iPhone",
# "inv": 99,
# "sku": 123124,
# }
# song = {
# "artist": "Arijit Singh",
# "song": "Some song",
# "track_time": 3.50,
# "band_members": [{"name": "member1", "age": 35}, {"name": "member2", "age": 40}],
# }
# my_playlist = [
# {
# "artist": "Arijit Singh",
# "song": "Some song",
# "track_time": 3.50,
# "band_members": [
# {"name": "member1", "age": 35},
# {"name": "member2", "age": 40},
# ],
# },
# {
# "artist": "Arijit Singh",
# "song": "Some song",
# "track_time": 3.50,
# "band_members": [
# {"name": "member1", "age": 35},
# {"name": "member2", "age": 40},
# ],
# },
# {
# "artist": "Arijit Singh",
# "song": "Some song",
# "track_time": 3.50,
# "band_members": [
# {"name": "member1", "age": 35},
# {"name": "member2", "age": 40},
# ],
# },
# ]
# song1 = {
# "artist": "Arijit Singh",
# "song": "Some song",
# "track_time": 3.50,
# "band_members": [
# {"name": "member1", "age": 35},
# {"name": "member2", "age": 40},
# ],
# }
# song2 = dict(artist="Arijit Singh", song="Some Song", track_time=3.50)
# book = {
# "name": "The theory of everything",
# "author": "Stephen Hawking",
# "pages": 140,
# "language": "English",
# "in_stock": True,
# 73: 1001001,
# }
player1 = "rock"
player2 = "rock"
if player1 == player2:
print("It's a tie")
elif player1 == "rock":
if player2 == "paper":
print("Player2 wins")
elif player2 == "scissors":
print("Player1 wins")
elif player1 == "paper":
if player2 == "rock":
print("Player1 wins")
elif player2 == "scissors":
print("Player2 wins")
elif player1 == "scissors":
if player2 == "rock":
print("Player2 wins")
elif player2 == "paper":
print("Player1 wins")
# if player1 == player2:
# print("It's a tie")
# elif player1 == "rock":
# if