Python Sunday

Python Sunday

Scratchpad #3

# num = 10
# print(f"This is some calculation: {num + 10}")


# print("Amount of USD you want to convert?")
# usd = input()
# inr = int(usd) * 75

# print(inr)

# print(f"You just typed this: {usd}")

# inr = int(usd) * 75

# print(f"${usd} is equal to Rs. {inr}")


# print("Enter your name: ")
# name = input()

# name = input("Enter your name: ")

# print(type(int(name)))


# print(<class 'int'>)

# name = "john doe"   # <-- assignment
# name == "john doe"  # <-- boolean value (comparison)

# name = "jack Doe"

# if name == "John Doe":
#     print("Hello John Doe")
# elif name == "Jane Doe":
#     print("Hello Jane")
# elif name == "Jack Doe":
#     print("Hello Jack")
# else:
#     print("I have no idea")


# if name == "Mark Zuckerberg":
#     print("Hello World")
#     print("Facebook")
# elif name == "Jack Dorsey":  # else if
#     print("Twitter")
# elif name == "Sundar Pichai":
#     print("Google")
# else:
#     print("Someone I don't know")


# print("\n\nI AM OUTSIDE OF THE CONDITIONALS")


# name = " "

# if name:
#     print("Hello friend")
# else:
#     print("Is anyone there...?")


# NESTED CONDITIONALS

# age = int(input("Please enter your age: "))

# if age >= 18:
#     print("You are allowed to enter but not drink")
# elif age >= 21:
#     print("You are allowed to drink")
# elif age >= 65:
#     print("Drinks are free")
# else:
#     print("You are not allowed!")


# if age >= 18:
#     if age >= 65:
#         print("Drinks are free")
#     elif age >= 21:
#         print("You are allowed to drink")
#     else:
#         print("You are allowed to enter but not drink")
# else:
#     print("You are not allowed!")


# age = int(input("Please enter your age: "))  # 38
# city = input("Please enter your city: ")  # delhi

# if (age >= 18 and age < 21) and city != "delhi":
#     print("You are allowed to enter but not drink")
# elif (age >= 21 and age < 65) and city != "delhi":
#     print("You are allowed to drink")
# elif age >= 65 and city != "delhi":
#     print("Drinks are free")
# else:
#     print("You are not allowed!")


# if city == "delhi":
#     print("You are not allowed!")
# elif age >= 18 and age < 21:
#     print("You are allowed to enter but not drink")
# elif age >= 21 and age < 65:
#     print("You are allowed to drink")
# elif age >= 65:
#     print("Drinks are free")
# else:
#     print("You are not allowed!")


# RPS

print("...rock...")
print("...paper...")
print("...scissors...")

player1 = input("enter Player 1's choice: ")  # rock
player2 = input("enter Player 2's choice: ")  # paper


# Original

if player1 == "rock" and player2 == "scissors":
    print("Player 1 wins")
elif player1 == "paper" and player2 == "rock":
    print("Player 1 wins")
elif player1 == "scissors" and player2 == "paper":
    print("Player 1 wins")
elif player2 == "rock" and player1 == "scissors":
    print("Player 2 wins")
elif player2 == "paper" and player1 == "rock":
    print("Player 2 wins")
elif player2 == "scissors" and player1 == "paper":
    print("Player 2 wins")
elif player1 == player2:
    print("It's a tie")
else:
    print("Something went wrong")


# Refactor #1

if (
    (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")
elif player1 == player2:
    print("It's a tie")
else:
    print("Something went wrong")


# Refactor #2

if player1 == player2:
    print("It's a tie!")
elif player1 == "rock":
    if player2 == "scissors":
        print("player1 wins!")
    elif player2 == "paper":
        print("player2 wins!")
elif player1 == "paper":
    if player2 == "rock":
        print("player1 wins!")
    elif player2 == "scissors":
        print("player2 wins!")
elif player1 == "scissors":
    if player2 == "paper":
        print("player1 wins!")
    elif player2 == "rock":
        print("player2 wins!")
else:
    print("Something went wrong")
# age = 14

# if age > 20:
#     if age > 30:
#         print("You are allowed and welcome")
#     elif age > 25:
#         print("You are allowed")
# else:
#     print("Not allowed")


# c[0] = r

# name = "rstforum"

# for c in name:
#     print(c)


# nums = range(1, 10)  # (1,2,3,4,5,6,7,8,9)

# for x in nums:
#     print("----")
#     print(x ** 2)
#     print("----")


# character = 'r'

# for char in "rstforum":
#     print(char)


# products = "COLLECTION"

# for product in products:
#     print(product)


# for num in range(10, 20):
#     print(num)

# for num in range(20):
#     print(num)


# "hello"[1, 5, 2]

# for num in range(0, 21, 5):  # (0, 5, 10, 15, 20)
#     print(num)


# for num in range(10, -20, -5):  # (1)
#     print(num)

# range(start=0, end, step=1)
# range(0, 10, 2)


# for i in range(10):
#     # print(i)
#     print("Hello World")


# for num in range(1, 10, 2):
#     print(num)


# Loop through numbers 1-20 (inclusive)
# for even numbers, you print, "Fizz is even"
# for odd numbers, you print, "Fizz is odd"
# for 5 and 16, print, "FizzBuzz"


# for num in range(1,21):
#     # num == 1  -> "Fizz is odd"
#     # num == 2  -> "Fizz is even"


# # for n in range(1, 21):
# #     if n % 2 ==

# 1 "Fizz is odd"
# 2 "Fizz is even"
# 3 "Fizz is odd"
# 4 "Fizz is even"
# 5 "FizzBuzz"
# 6 "Fizz is even"
# 7 "Fizz is odd"


# # Loop through numbers 1-20 (inclusive)
# for num in range(1, 21):
#     if num == 5 or num == 16:  # for 5 and 16, print, "FizzBuzz"
#         print(num, "FizzBuzz")
#     elif num % 2 == 0:  # for even numbers, you print, "Fizz is even"
#         print(num, "Fizz is even")
#     else:  # for odd numbers, you print, "Fizz is odd"
#         print(num, "Fizz is odd")


# password = input("Please enter your password: ")
# # 'hello'

# while password != "pass@123":
#     print("Incorrect password!")
#     password = input("Enter password again: ")


# print("Welcome")


# for num in range(10):
#     print(num)


# num = 0
# while num < 10:
#     print(num)
#     num += 1  # num = num + 1


name = "rstforum"

num = 0
while num < len(name):
    print(name[num])
    num += 1
# name = "John Doe"
# value = 2500
# paid = True

# # Data structures
# # collections of things

# # Lists
# tasks = "buy milk|pay electricity bill|complete labs"

# tasks = ["buy milk", "pay bill", "complete labs", 1000, True]

# product = ["iPhone", "Apple", 80000, 100]


# tasks = ["Install Python", "Install VSCode", "Setup Auto PEP8"]

# first_task = "Install Black"
# second_task = "Install VSCode Pylance extension"
# third_task = "Setup Python 3.9.1"

# tasks = [2021, first_task, second_task, third_task, "Install Windows Terminal"]


# print(tasks)
# print(type(tasks))


# print(len(tasks))


# nums_list = list(range(1, 51))

# print(nums_list)
# print(len(nums_list))


# tasks = [
#     "Install Python",
#     "Install VSCode",
#     "Setup Auto PEP8",
#     "Install Black",
#     "Install VSCode Pylance extension",
# ]

# for task in tasks:
#     print(f"Task is - {task.upper()}")


# i = 0
# while i < len(tasks):
#     print(f"Task {i + 1} - {tasks[i]}\n")
#     i += 1


# nums = list(range(1, 10))  # [1,2,3,4,5,6,7,8,9]

# for num in nums:
#     print(num ** 2)


# >>>
# >>>
# >>> name = "john"
# >>>
# >>>
# >>> len(name)
# 4
# >>>
# >>> name.upper()
# 'JOHN'
# >>>
# >>>
# >>>
# >>>
# >>>
# >>> tasks = ["Install Python", "Install VSCode", "Setup Auto PEP8"]
# >>>
# >>>
# >>> tasks
# ['Install Python', 'Install VSCode', 'Setup Auto PEP8']
# >>>
# >>>
# >>> tasks.append("Install Windows Terminal")
# >>>
# >>>
# >>> tasks
# ['Install Python', 'Install VSCode', 'Setup Auto PEP8', 'Install Windows Terminal']
# >>>
# >>>
# >>> name.upper()
# 'JOHN'
# >>>
# >>>
# >>>
# >>> random_numbers = [1, 4, 34, 21, 86]
# >>>
# >>>
# >>> randon_numbers
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'randon_numbers' is not defined
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86]
# >>>
# >>>
# >>> random_numbers.append(100)
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86, 100]
# >>>
# >>> random_numbers.append(100)
# >>>
# >>> random_numbers.append(10)
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86, 100, 100, 10]
# >>>
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86, 100, 100, 10]
# >>>
# >>> random_numbers.append(100, 50, 40)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: list.append() takes exactly one argument (3 given)
# >>>
# >>>
# >>>
# >>> random_numbers.append(True)
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86, 100, 100, 10, True]
# >>> random_numbers.append("John Doe")
# >>>
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86, 100, 100, 10, True, 'John Doe']
# >>>
# >>> random_numbers.append(100 ** 3)
# >>>
# >>> random_numbers
# [1, 4, 34, 21, 86, 100, 100, 10, True, 'John Doe', 1000000]

# >>> nums = list(range(5))
# >>>
# >>>
# >>> nums
# [0, 1, 2, 3, 4]
# >>>
# >>>
# >>> nums.append([5,6,7,8])
# >>>
# >>> nums
# [0, 1, 2, 3, 4, [5, 6, 7, 8]]
# >>>
# >>>
# >>> len(nums)
# 6
# >>>
# >>> nums[-1]
# [5, 6, 7, 8]
# >>>
# >>> nums = list(range(5))
# >>>
# >>>
# >>>
# >>> nums
# [0, 1, 2, 3, 4]
# >>>
# >>>
# >>> nums.extend([5,6,7,8,9,10])
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# >>>
# >>> len(nums)
# 11
# >>>
# >>>
# >>>
# >>> nums.extend([100, True, False, "john doe"])
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, True, False, 'john doe']
# >>>
# >>> nums.extend(list(range(100,110)))
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, True, False, 'john doe', 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]
# >>>
# >>>
# >>>

# >>> nums.insert(0, "Hello World")
# >>>
# >>> nums
# ['Hello World', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, True, False, 'john doe', 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]
# >>>
# >>>
# >>>
# >>> nums.insert(3, 1.111112)
# >>>
# >>> nums
# ['Hello World', 0, 1, 1.111112, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, True, False, 'john doe', 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]
# >>>
# >>>
# >>> nums.insert(-1, "ENDING")
# >>>
# >>> nums
# ['Hello World', 0, 1, 1.111112, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, True, False, 'john doe', 100, 101, 102, 103, 104, 105, 106, 107, 108, 'ENDING', 109]
# >>>
# >>>
# >>>
# >>> nums
# ['Hello World', 0, 1, 1.111112, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, True, False, 'john doe', 100, 101, 102, 103, 104, 105, 106, 107, 108, 'ENDING', 109]
# >>>
# >>>
# >>>
# >>> nums.clear()
# >>>
# >>> nums
# []
# >>>
# >>> bool(nums)
# False

# >>> tasks = ["Install Python", "Install VSCode", "Setup Auto PEP8"]
# >>>
# >>>
# >>> tasks
# ['Install Python', 'Install VSCode', 'Setup Auto PEP8']
# >>>
# >>>
# >>>
# >>>
# >>>
# >>> tasks.pop()
# 'Setup Auto PEP8'
# >>>
# >>> tasks
# ['Install Python', 'Install VSCode']
# >>>
# >>>
# >>>
# >>> deleted_item = tasks.pop()
# >>>
# >>> delete_item
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'delete_item' is not defined
# >>>
# >>> deleted_item
# 'Install VSCode'
# >>>
# >>> tasks
# ['Install Python']
# >>>
# >>>
# >>>
# >>> tasks = ["Install Python", "Install VSCode", "Setup Auto PEP8"]
# >>>
# >>>
# >>>
# >>> tasks
# ['Install Python', 'Install VSCode', 'Setup Auto PEP8']
# >>>
# >>>
# >>> tasks(1)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'list' object is not callable
# >>>
# >>> tasks.pop(1)
# 'Install VSCode'
# >>>
# >>>
# >>> tasks
# ['Install Python', 'Setup Auto PEP8']
# >>> tasks.pop(0)
# 'Install Python'
# >>>
# >>>
# >>> tasks
# ['Setup Auto PEP8']
# >>>
# >>> tasks = ["Install Python", "Install VSCode", "Setup Auto PEP8"]
# >>>
# >>>
# >>> tasks
# ['Install Python', 'Install VSCode', 'Setup Auto PEP8']
# >>>
# >>>
# >>> task.remove("Install Python")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'task' is not defined
# >>>
# >>>
# >>> tasks.remove("Install Python")
# >>>
# >>> tasks
# ['Install VSCode', 'Setup Auto PEP8']
# >>>
# >>> tasks.remove("Install Python")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: list.remove(x): x not in list
# >>>
# >>> tasks.remove()
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: list.remove() takes exactly one argument (0 given)
# >>>
# >>> tasks
# ['Install VSCode', 'Setup Auto PEP8']
# >>>
# >>> tasks.remove("Setup Auto POP8")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: list.remove(x): x not in list
# >>>
# >>> tasks.remove("Setup Auto PEP8")
# >>>
# >>> tasks
# ['Install VSCode']


# >>> tasks = [
# ...     "Install Python",
# ...     "Install VSCode",
# ...     "Setup Auto PEP8",
# ...     "Install Black",
# ...     "Install VSCode Pylance extension",
# ... ]
# >>>
# >>>
# >>>
# >>>
# >>> tasks = [
# ...     "Test 1",
# ...     "Install Python",
# ...     "Install VSCode",
# ...     "Test 1",
# ...     "Install Black",
# ...     "Setup Auto PEP8",
# ...     "Install Black",
# ...     "Install VSCode Pylance extension",
# ...     "Practice Lab",
# ...     "Test 1"
# ...     "Install VSCode",
# ...     "Install Black",
# ...     "Install VSCode Pylance extension",
# ... ]
# >>>
# >>>
# >>>
# >>> tasks
# ['Test 1', 'Install Python', 'Install VSCode', 'Test 1', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Install VSCode Pylance extension', 'Practice Lab', 'Test 1Install VSCode', 'Install Black', 'Install VSCode Pylance extension']
# >>>
# >>> len(tasks)
# 12
# >>>
# >>>
# >>> tasks.index("Test 1")
# 0
# >>>
# >>> tasks.index("Install Black")
# 4
# >>>
# >>> tasks
# ['Test 1', 'Install Python', 'Install VSCode', 'Test 1', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Install VSCode Pylance extension', 'Practice Lab', 'Test 1Install VSCode', 'Install Black', 'Install VSCode Pylance extension']
# >>>
# >>>
# >>> tasks.index("Test 1")
# 0
# >>>
# >>>
# >>> tasks.index("Test 1", 2)
# 3
# >>> tasks.index("Test 1", 2, 8)
# 3
# >>> tasks.index("Install Black", 2, 8)
# 4
# >>>
# >>> tasks.index("Install Black", 5, 8)
# 6
# >>> tasks.index("Install Black", 7, 10)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: 'Install Black' is not in list
# >>>
# >>>
# >>>
# >>> tasks
# ['Test 1', 'Install Python', 'Install VSCode', 'Test 1', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Install VSCode Pylance extension', 'Practice Lab', 'Test 1Install VSCode', 'Install Black', 'Install VSCode Pylance extension']
# >>>
# >>>
# >>>
# >>> tasks.count("Test 1")
# 2
# >>>
# >>> tasks.count("Install Black")
# 3
# >>>
# >>> tasks.count("Install Bla")
# 0
# >>>
# >>> tasks.count("Install Python")
# 1
# >>>
# >>> \
# ...
# >>>
# >>>
# >>>
# >>>
# >>> tasks
# ['Test 1', 'Install Python', 'Install VSCode', 'Test 1', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Install VSCode Pylance extension', 'Practice Lab', 'Test 1Install VSCode', 'Install Black', 'Install VSCode Pylance extension']
# >>>
# >>> tasks.reverse()
# >>>
# >>> tasks
# ['Install VSCode Pylance extension', 'Install Black', 'Test 1Install VSCode', 'Practice Lab', 'Install VSCode Pylance extension', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Test 1', 'Install VSCode', 'Install Python', 'Test 1']
# >>>
# >>>
# >>>
# >>> nums = list(range(10))
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>> nums.reverse()
# >>> nums
# [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
# >>>
# >>>
# >>>
# >>>
# >>>
# >>> nums
# [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
# >>>
# >>>
# >>> nums.sort()
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>> tasks
# ['Install VSCode Pylance extension', 'Install Black', 'Test 1Install VSCode', 'Practice Lab', 'Install VSCode Pylance extension', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Test 1', 'Install VSCode', 'Install Python', 'Test 1']
# >>>
# >>>
# >>>
# >>> names = ['john', 'mohsin', 'suyog', 'deepak', 'yashika', 'sandeep', 'umesh', 'akshay']
# >>>
# >>> names
# ['john', 'mohsin', 'suyog', 'deepak', 'yashika', 'sandeep', 'umesh', 'akshay']
# >>>
# >>> names.sort()
# >>>
# >>> names
# ['akshay', 'deepak', 'john', 'mohsin', 'sandeep', 'suyog', 'umesh', 'yashika']
# >>>
# >>> l = [True, False, 123, "john"]
# >>>
# >>> l.sort()
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: '<' not supported between instances of 'str' and 'bool'
# >>>
# >>>
# >>>
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>>
# >>> nums.reverse()
# >>>
# >>> nums
# [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
# >>>
# >>>
# >>>
# >>>
# >>> "-".join("john")
# 'j-o-h-n'
# >>>
# >>> "-".join([1,2,3,4])
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: sequence item 0: expected str instance, int found
# >>>
# >>> "-".join(nums)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: sequence item 0: expected str instance, int found
# >>>
# >>>
# >>>
# >>>
# >>>
# >>> "".join(nums)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: sequence item 0: expected str instance, int found
# >>>
# >>>
# >>>
# >>>
# >>>
# >>>
# >>> "".join()
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: str.join() takes exactly one argument (0 given)
# >>> "".join(nums)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: sequence item 0: expected str instance, int found
# >>>
# >>>
# >>>
# >>>
# >>> "".join(tasks)
# 'Install VSCode Pylance extensionInstall BlackTest 1Install VSCodePractice LabInstall VSCode Pylance extensionInstall BlackSetup Auto PEP8Install BlackTest 1Install VSCodeInstall PythonTest 1'
# >>>
# >>>
# >>>
# >>>
# >>> nums
# [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
# >>>
# >>>
# >>>
# >>> "".join(["john", "jack", "jane"])
# 'johnjackjane'
# >>>
# >>> "____".join(["john", "jack", "jane"])
# 'john____jack____jane'
# >>>
# >>>
# >>>
# >>> "" + 12
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: can only concatenate str (not "int") to str
# >>>
# >>>
# >>> "____".join(["john", "jack", "jane"])
# 'john____jack____jane'
# >>>
# >>> tasks
# ['Install VSCode Pylance extension', 'Install Black', 'Test 1Install VSCode', 'Practice Lab', 'Install VSCode Pylance extension', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Test 1', 'Install VSCode', 'Install Python', 'Test 1']
# >>>
# >>>
# >>>
# >>> "____".join(tasks)
# 'Install VSCode Pylance extension____Install Black____Test 1Install VSCode____Practice Lab____Install VSCode Pylance extension____Install Black____Setup Auto PEP8____Install Black____Test 1____Install VSCode____Install Python____Test 1'
# >>>
# >>> tasks
# ['Install VSCode Pylance extension', 'Install Black', 'Test 1Install VSCode', 'Practice Lab', 'Install VSCode Pylance extension', 'Install Black', 'Setup Auto PEP8', 'Install Black', 'Test 1', 'Install VSCode', 'Install Python', 'Test 1']
# >>>
# >>>
# >>>
# >>>
# >>>
# >>> nums
# [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
# >>>
# >>>
# >>>
# >>> nums.sort()
# >>>
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>>
# >>>
# >>>
# >>> nums[1]
# 1
# >>>
# >>> nums[1:]
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>> nums[5:]
# [5, 6, 7, 8, 9]
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>>
# >>> nums[5:8]
# [5, 6, 7]
# >>>
# >>> nums[:8]
# [0, 1, 2, 3, 4, 5, 6, 7]
# >>>
# >>> nums[:]
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>> nums_copy = nums[:]
# >>>
# >>>
# >>> nums_copy
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>>
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>>
# >>> nums[6:-1]
# [6, 7, 8]
# >>>
# >>>
# >>> nums[0:-1]
# [0, 1, 2, 3, 4, 5, 6, 7, 8]
# >>>
# >>> nums[:]
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# >>>
# >>> nums[::2]
# [0, 2, 4, 6, 8]
# >>>
# >>> nums[::3]
# [0, 3, 6, 9]
# >>>
# >>>
# >>>
# >>> nums[::-1]
# [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
# >>>
# >>> nums
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


# tasks = [
#     "Test 1",
#     "Install Python",
#     "Install VSCode",
#     "Test 1",
#     "Install Black",
#     "Setup Auto PEP8",
#     "Install Black",
#     "Install VSCode Pylance extension",
#     "Practice Lab",
#     "Test 1"
#     "Install VSCode",
#     "Install Black",
#     "Install VSCode Pylance extension",
# ]
# names = ["john", "jane", "jack", "james"]

# # upper_names = []

# # # for name in names:
# # #     print(name.upper())

# # for name in names:
# #     upper_names.append(name.upper())

# # print(names)
# # print(upper_names)


# upper_names = [name.upper() for name in names]

# print(upper_names)


# nums = range(1, 21)

# evens = [num for num in nums if num % 2 == 0]
# odds = [num for num in nums if num % 2 != 0]

# new = [num * 2 if num % 2 == 0 else num / 2 for num in nums]

# print(evens)
# print(odds)
# print(new)


# message = "Hello Python!"

# "".join([char for char in message if char not in "aeiou"])


# nested_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]


# for lst in nested_list:
#     for item in lst:
#         print(item)


product = {
    "name": "AMD Ryzen Threadripper 3990X",
    "no_of_cores": 64,
    "no_of_threads": 128,
    "unlocked": True,
    "memory_type": "DDR4",
    "price": 333999.00,
    1: True,
}


# product = ["AMD Ryzen Threadripper 3990X", 64, 128, True]
# def say_hello():
#     print("Hello World!")
#     print("Hello World!")
#     print("Hello World!")


# # print(say_hello)

# say_hello()
# say_hello()


# def say_hello():
#     return "Hello World!"


def say_hello():
    print("Hello World!")
    # return "Hello World!"


# def give_a_num():
#     num = 10 * 3
#     return num
#     print("I am done")


# # result = "Hello World!"

# print(result)

# print(say_hello())


# print(give_a_num() + 10)

# print("Calling say_hello returns: ", say_hello())


# print(type(give_a_num()))
# print(type(say_hello()))

# print(give_a_num())


def say_hello():
    return "hello world, from say_hello"


def print_hello():
    print(say_hello())


def exec():
    print_hello()


exec()
# def say_hello():
#     print("TEST")


# print(say_hello())


# from random import random


# def flip_coin():
#     r = random()
#     if r > 0.5:
#         return "Heads"
#     else:
#         return "Tails"


# print(flip_coin())


# def add(num1, num2):
#     return num1 + num2


# def multiply(a, b, c, d, e):
#     return a * b * c * d * e


# print(add(100, 50))
# print(multiply(10, 2, 3, 4, 65))


# def say(name, message):
#     return f"{name} says, {message}"


# print(say("John", "Hello World!"))
# print(say("Jane", "Hello World!"))
# print(say("Jack", "Hello World!"))
# print("Finished")


# def sum_odd_numbers(numbers):
#     total = 0
#     for num in numbers:
#         if num % 2 != 0:
#             total += num
#     return total


# print(sum_odd_numbers([1, 2, 3, 4, 5, 6, 7, 8]))


# def is_odd_number(number):
#     if number % 2 != 0:
#         return True
#     return False


# print(is_odd_number(5))
# print(is_odd_number(2))


# def exponent(num=2, power=1):
#     return num ** power


# # print(exponent())
# # print(exponent(3, 4))
# # print(exponent(7))


# def say(name, message="Hello"):
#     return f"{name} says, {message}"


# print(say("John"))
# print(say("John", exponent(10, 4)))


# def add(a, b):
#     return a + b


# def subtract(a, b):
#     return a - b


# def divide(a, b):
#     return a / b


# print(add, subtract)


# def math(a, b, fn):
#     return fn(a, b)


# print(math(10, 2, add))
# print(math(10, 2, subtract))
# print(math(10, 2, divide))


# def print_name(first_name="john", last_name="doe"):
#     print(f"My first name is {first_name} and my last name is {last_name}")


# # print_name("John", "Doe")
# # print_name("Doe", "John")

# # print_name(last_name="Doe", first_name="John")

# print_name(last_name="Ma")
def names(*names):
    for name in names:
        print(name)


# # names("John", "Jack")
# names("John", "Jack", "James", "Jane", "Jayesh")


def sum_nums(*nums):
    total = 0
    for num in nums:
        total += num
    return total


# print(sum_nums(10, 20, 4, 3, 6, 4, 7, 6, 12, 98))
# print(sum_nums())


def sum_all_nums(name, main_num, *nums):
    total = 0
    for num in nums:
        total += num
    return f"Hello {name}:{main_num}, the result is {total}."


# print(sum_all_nums("John", 4, 56, 6, 4, 332, 223, 4))


def user_details(message, **info):
    print(info)
    print(f"{message}\n")
    for k, v in info.items():
        print(f"{k} --- {v}")


# user_details(
#     "Here are the details:", name="John", age=25, job="Python Programmer", status=False
# )


def show_info(a, b, *args, job="Programmer", **kwargs):
    print(a, b, args, job, kwargs)


# show_info(
#     "John",
#     "Doe",
#     3,
#     45,
#     6,
#     True,
#     False,
#     job="Python Developer",
#     age=25,
#     city="Kajupada",
# )


# def show_info(a, b, *args, role="moderator", **kwargs):
#     return [a, b, args, role, kwargs]


# print(show_info(1, 2, 3, first_name="John", last_name="Doe"))


def add_all_values(*args):
    total = 0
    for num in args:
        total += num
    print(total)


# add_all_values(102, 45, 323, 2, 23, 45, 56)


# nums = [1, 2, 3, 4, 5, 6, 7, 8]

# add_all_values(nums[0], nums[1], nums[2])
# add_all_values(*nums)

# add_all_values(1, 2, 3, 4, 5, 6, 7, 8)


def say_name(first, last):
    print(f"My name is {first} {last}.")


# say_name(first="John", last="Doe")

# name = {"first": "Robert", "last": "Moore"}

# say_name(**name)


# def hello(name):
#     return name


# print(hello("John"))


# def square(num):
#     return num * num


# square = lambda num: num * num


# print(square(10))


def math(a, b, fn):
    return fn(a, b)


# def add(a, b):
#     return a + b


# print(math(10, 5, add))

# print(math(10, 20, lambda x, y: x + y))
# print(math(10, 20, lambda x, y: x - y))


# say_name = lambda name: name.upper()

# def say_name(name):
#     return name.upper()

# print(say_name("john doe"))


# nums = [1,2, 3, 4, 5, 6, 7, 8]

# squared_vals = map(lambda x: x ** 2, nums)
# print(tuple(squared_vals))

# squared_vals = [val ** 2 for val in nums]
# print(squared_vals)

# squared_vals = []
# for val in nums:
#     squared_vals.append(val ** 2)

# print(squared_vals)


# nums = [1, 2, 3, 4, 5, 6, 7, 8]

# squared_vals = map(lambda x: x ** 2, nums)
# # print(squared_vals)


# for num in squared_vals:
#     print(f"The result is {num}")


# names = ["john", "james", "jim", "jack", "jane", "jill"]

# uppercased_names = list(map(lambda name: name.upper(), names))

# print(uppercased_names)


# nums = [1, 2, 3, 4, 5, 6, 7, 8]

# result = list(filter(lambda x: x % 2 == 0, nums))

# print(result)


# names = ["john", "james", "jim", "jack", "jane", "jill"]

# print(list(filter(lambda name: len(name) <= 4, names)))


names = ["John", "Jack", "James", "Desmond", "Charlie", "Jacob"]

filter_names = filter(lambda name: len(name) < 5, names)

res = map(
    lambda name: f"The one who wins is {name}",
    filter_names,
)

for name in res:
    print(name)
def colorize(text, color):
    """Function that prints text in color"""
    colors = ("red", "yellow", "blue", "green", "purple")

    if type(text) is not str:
        raise TypeError("Text must be a string")
    if type(color) is not str:
        raise TypeError("Color must be a string")
    if color not in colors:
        raise ValueError("Color is invalid")


#     print(f"Printed {text} in {color}")


# colorize("hello world", "blue")
# colorize("Goodbye World!", "orange")
# colorize(100, "yellow")


# try:
#     # 100 / 0
#     colorize(100, "yellow")
# except (ZeroDivisionError, ValueError):
#     print("Some error happened")

# try:
#     # 100 / 0
#     colorize(100, "yellow")
# except Exception as error:
#     print("Some error happened -> ", error)

# print("This code happens after the try/except")


# try:
#     num = int(input("Please enter a number: "))
# except:
#     print("Please enter digits")
# else:
#     print("Text from the else block", num)
# finally:
#     print("This will always run")


# import random as r

# print(r.random())
# print(r.randint(0, 50))

# my_list = [1, 2, 3, 4, 5]
# r.shuffle(my_list)
# print(my_list)


from random import random as r, randint as ri

# from random import *

print(r())
print(ri(0, 30))
# print(choice([1, 2, 4, 5, 6]))
# class User:
#     def __init__(self, first, last, age):
#         self.first_name = first
#         self.last_name = last
#         self.age = age
#         self.country = "India"
#         self.active = False


# john = User("John", "Doe", 25)  # User Object/Instance
# jane = User("Jane", "Doe", 30)


# print(john.first_name, john.last_name, john.age, john.country, john.active)
# print(jane.first_name, jane.last_name, jane.age, jane.country)


# john.first_name = "JOHN"
# john.age = john.age + 1
# john.active = True

# print(john.first_name, john.last_name, john.age, john.country, john.active)


# def user(first_name, last_name, age):
#     data = {"first_name": first_name, "last_name": last_name, "age": age}
#     return data


# john = user("john", "doe", 25)
# jane = user("jane", "doe", 30)

# print(john["first_name"], john["last_name"], john["age"])

# john["first_name"] = "JOHN"

# print(john["first_name"], john["last_name"], john["age"])


# class BankAccount:
#     def __init__(self, first, last, age, balance=0):
#         self.first_name = first
#         self.last_name = last
#         self.age = age
#         self.__balance = balance


# john = BankAccount("John", "Doe", 25)
# jane = BankAccount("Jane", "Doe", 30, 5000)


# print(john.first_name, john._BankAccount__balance)
# print(jane.first_name, jane._BankAccount__balance)

# john.first_name = "JOHN"
# john._BankAccount__balance = 2000

# print(john.first_name, john._BankAccount__balance)


class BankAccount:
    total_customers = 0
    online_users = 0

    def __init__(self, first, last, age, balance=0):
        self.first_name = first
        self.last_name = last
        self.age = age
        self._balance = balance
        BankAccount.total_customers += 1

    def get_balance(self):
        print(f"Your current balance is {self._balance} INR")
        return self._balance

    def deposit(self, amount):
        self._balance = self._balance + amount
        print(
            f"{amount} INR was deposited to your account\nYour new balance is {self._balance} INR"
        )
        return self._balance

    def login(self):
        BankAccount.online_users += 1
        print("You have successfully logged in")

    def logout(self):
        BankAccount.online_users -= 1
        print("You have successfully logged out")

    @classmethod
    def get_total_customers(cls):
        print(f"Your Bank has {cls.total_customers} customer(s)")
        return cls.total_customers


john = BankAccount("John", "Doe", 25)
jane = BankAccount("Jane", "Doe", 30, 5000)


john.get_balance()
john.deposit(1000)
john.deposit(540)

john.login()

# print(john.total_customers, jane.total_customers)
print(BankAccount.total_customers)
print(BankAccount.online_users)

john.logout()

print(BankAccount.online_users)

BankAccount.get_total_customers()


# class Math:
#     @classmethod
#     def add(cls, num1, num2):
#         return num1 + num2

#     @classmethod
#     def sub(cls, num1, num2):
#         return num1 - num2

#     @classmethod
#     def mul(cls, num1, num2):
#         return num1 * num2


# print(Math.sub(10, 20))
# print(Math.add(10, 20))
# class User:
#     def __init__(self, first, last, age):
#         self.first_name = first
#         self.last_name = last
#         self.age = age

#     def __repr__(self):
#         return f"User Object\nFirst Name: {self.first_name}\nAge: {self.age}\n"


# john = User("John", "Doe", 25)
# jane = User("Jane", "Doe", 30)

# print(john)
# print(jane)


# class Animal:
#     def __init__(self, type, sound):
#         self.type = type
#         self.sound = sound

#     def __repr__(self):
#         return f"I am a {self.type} and I say {self.sound}"

#     def make_sound(self):
#         return f"{self.sound * 3}"


# class Dog(Animal):
#     def __init__(self, type, sound, color):
#         super().__init__(type, sound)
#         self.color = color

#     def do_tricks(self):
#         return "I did a trick"


# class Cat(Animal):
#     def __init__(self, color, breed, age):
#         # self.type = "Cat"
#         # self.sound = "Meow"
#         super().__init__("Cat", "Meow")
#         self.color = color
#         self.breed = breed
#         self._age = age

#     def eat(self, food_type):
#         return f"My {self.breed} just ate {food_type}"

#     @property
#     def age(self):
#         print("You will getting the age")
#         return self._age

#     @age.setter
#     def age(self, new_age):
#         self._age = new_age
#         return "Age has been updated"

#     def get_age(self):
#         return self._age

#     def set_age(self, new_age):
#         self._age = new_age
#         return "Age has been updated"


# tyson = Dog("Bulldog", "BARK", "grey")
# print(tyson)


# sherkhan = Animal("Lion", "Roar")
# gabbar = Dog("red")
# billa = Cat("green", "Kajupada", 5)

# print(billa.age)
# billa.age = 12
# print(billa.age)

# print(sherkhan)
# print(sherkhan.make_sound())
# print(gabbar)
# print(gabbar.make_sound())

# print(type(sherkhan))
# print(type(gabbar))

# print(gabbar.do_tricks())
# print(gabbar.color)
# print(billa.eat("fish"))
# # print(billa._age)
# billa.set_age(6)
# billa.color = "purple"
# print(billa.get_age())
# print(billa.color)

# print(sherkhan.color)


class Human:
    def __init__(self, name):
        self.name = name

    def think(self):
        return f"THINKING...."

    # def speak(self):
    #     return f"My name is {self.name} and I am Human"


class Animal:
    def __init__(self, name):
        self.name = name

    def sprint(self):
        return "SPRINTING..."

    def speak(self):
        return f"asdasdasd sad {self.name} Animal..asd.asd"


class Mutant(Human, Animal):
    def __init__(self, name):
        self.name = name


bheem = Human("Bheem")
kutta = Animal("Jaggu")
wolverine = Mutant("Logan")

# print(bheem.speak())
# print(kutta.speak())
print(wolverine.speak())

print(help(Mutant))
# # class Animal:
# #     def speak(self):
# #         raise NotImplementedError("Subclass needs to implement this method")


# # class Dog(Animal):
# #     def speak(self):
# #         return "bark"


# # class Cat(Animal):
# #     def speak(self):
# #         return "meow"


# # ben = Cat()

# # print(ben.speak())


# # def simpleFunction():
# #     raise ValueError("This is some error")


# # simpleFunction()


# class Animal:
#     def __init__(self, name):
#         self.name = name


# class Human:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age

#     def __repr__(self):
#         return self.name

#     def __len__(self):
#         return self.age

#     def __gt__(self, other):
#         return self.age > other.age

#     def __add__(self, other):
#         if isinstance(other, Human):
#             return Human("new born", 0)
#         else:
#             raise TypeError("Humans can't be added with non-Humans")


# john = Human("John Doe", 25)
# jane = Human("Jane Doe", 30)
# sherkhan = Animal("Sherkhan")

# # print(john)
# # print(len(john))

# # print(john + sherkhan)
# print(john > jane)


# def my_for(fn, iterable):
#     iterator = iter(iterable)

#     while True:
#         try:
#             fn(next(iterator))
#         except StopIteration:
#             break


# for num in [1,2,3]:
#     print(num * num)


# # my_for(["john", "jack", "jane"])


# my_for(lambda x: print(x * x), [1, 2, 3, 4, 5, 6])


# def count_to(max):
#     count = 1
#     while count <= max:
#         yield count
#         count += 1


# res = count_to(10)

# for num in res:
#     print(num * 2)


# def fib_list(max):
#     nums = []
#     a, b = 0, 1
#     while len(nums) < max:
#         nums.append(b)
#         a, b = b, a + b
#     return nums


# def fib_gen(max):
#     a, b = 0, 1
#     count = 0
#     while count < max:
#         a, b = b, a + b
#         yield a
#         count += 1


# print(fib_list(100000))
# print(fib_gen(100000))


# for num in fib_gen(100000):
#     print(num)

# import time

# list_start_time = time.time()
# print(sum([num for num in range(100000000)]))
# list_total_time = time.time() - list_start_time


gen_start_time = time.time()
print(sum(num for num in range(1000000000)))
gen_total_time = time.time() - gen_start_time


print(f"List comp took: {list_total_time}")
print(f"Gen Exp took: {gen_total_time}")


def counter_generator(start, end, step=1):
    while start <= end:
        yield start
        start += step

# val = counter_generator(0, 10, 2)

# # for v in val:
# #     print(v)

# print(list(val))


# Bank
#   ---- class attr -> total_banks
#   ---- class method -> get_total_banks()
#   __repr__
#   name
#   initials
#   address
#   phone no
#   IFSC
#   Customers (list)
# ----- methods ------
#   add_new_customer(customer_obj)
# ->
#   find_customer_by_acc()
#   find_customers_by_name() -> return a list

# Customer
#   __repr__
#   first_name
#   last_name
#   phone
#   email
#   address
#   account_no
#   balance = 5000
# ------ methods ------
#   withdraw()
#   deposit()
#   change_details()

# sbi = Bank("Bank of India", "BOI")


# rahul@rstforum.co.in