Well,I learn coding.So,I wanna add some of my codes.You have to run it in thonny or other IDE softwares.Here are some:
fruit_list = input().split()
# Sort the fruit list alphabetically
sorted_fruit_list = sorted(fruit_list)
# Print the sorted fruit list with the index
for index, fruit in enumerate(sorted_fruit_list, start=1):
print(f"Item {index}:{fruit}")
Here,add some names with spaces,and you will see a list of it.
A,B=map(int,input().split())
print(A+B)
Here,input two numbers,and it will add them.
T=int(input())
for _ in range(T):
a,b,c=map(int,input().split())
print(max(a,b,c))
Here,in first line,add how many tests you want to do.Then,add three numbers and it will find the max number among them.
height, width = map(float, input().split())
area = height * width
print(area)
Here,add to numbers of the rectangle.First one is height,second one is width.It will give you the answer.
def is_anadrome(word):
return word==word[::-1]
word=str(input())
if is_anadrome(word):
print("Yes")
else:
print("No")
Enter any text,if it is same from front to back and back to front,it will say yes.Otherwise no.
import math
# Function to count set bits in a number
def count_set_bits(n):
count = 0
while n:
count += n & 1
n >>= 1
return count
# Function to check if a number is prime
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
# Function to check if a number is binary prime
def is_binary_prime(n):
set_bits_count = count_set_bits(n)
if is_prime(set_bits_count):
return "Binary prime"
else:
return "-1"
# Main function
if __name__ == "__main__":
T = int(input().strip())
for _ in range(T):
N = int(input().strip())
print(is_binary_prime(N))
Input any number.If that isprime,it will show yes.It will convert the number to binary,then add all the numbers,then if it is prime,it will say yes,otherwise no.
import random
while True:
choices = ["rock", "paper", "scissors"]
computer = random.choice(choices)
player = None
while player not in choices:
player = input("rock,paper or scissors?: ").lower()
if player == computer:
print("computer: ", computer)
print("player: ", player)
print("Tie!")
elif player == "rock":
if computer == "paper":
print("computer: ", computer)
print("player: ", player)
print("You lose!")
if computer == "scissors":
print("computer: ", computer)
print("player: ", player)
print("You win!")
elif player == "paper":
if computer == "scissors":
print("computer: ", computer)
print("player: ", player)
print("You lose!")
if computer == "rock":
print("computer: ", computer)
print("player: ", player)
print("You win!")
elif player == "scissors":
if computer == "rock":
print("computer: ", computer)
print("player: ", player)
print("You lose!")
if computer == "paper":
print("computer: ", computer)
print("player: ", player)
print("You win!")
play_again = input("Play again? (yes/no):").lower()
if play_again != "yes":
break
print("Bye!")
Simple rock,paper,scissors game.
Currently,learning C, solving problems in Toph,CoderOJ etc.You can find me there.My profile name is Muntasir Mahmud.