<jupyter_start><jupyter_text>If - elif - else statement<jupyter_code>#W. A P. which takes one number from 0 to 9 from the user and prints it in the word. And if the word is wenot from 0 to 9 then
#it should print that number is outside of the range and program should exit.
# For exapmple:- 
# input = 1
# output = one

num = int(input("Enter the number: "))
num_list = ['zero','one','two','three','four','five','six','seven','eight','nine']
if num < 0 or num>9:
    print("Out of range input")
else:
    print(num_list[num])

#W. A P. to implement calculator but the operation to be done and two numbers will be taken as input from user:-
#Operation console should show below:-
#     Please select any one operation from below:-
#         * To add enter 1
#         * to subtract enter 2
#         * To multiply enter 3
#         * To divide enter 4
#         * To divide and find quotient enter 5
#         * To divide and find remainder enter 6
#         * To divide and find num1 to the power of num2 enter 7
#         * To Come out of the program enter 8

a = int(input("Enter the 1st number: "))
b = int(input("Enter the 2nd number: "))
c = int(input("What opeartion do you want? "))
if c==1:
    print(a+b)
elif c==2:
    print(abs(a-b))
elif c==3:
    print(a*b)
elif c==4:
    print(a/b)
elif c==5:
    print(a//b)
elif c==6:
    print(a%b)
elif c==7:
    print(a**b)
elif c==8:
    exit()
else:
    print("Wrong input given")

#W A P to check whether a year entered by user is an leap year or not?
#Check with below input:-
    #leap year:- 2012, 1968, 2004, 1200, 1600,2400
    #Non-lear year:- 1971, 2006, 1700,1800,1900
    
year = int(input("Enter the year: "))
if year % 4 == 0 and year % 100 != 0:
    print("Leap year")
elif year % 400 == 0:
    print("Leap year")
else:
    print("Not a Leap year")
#W A P which takes one number from the user and checks whether it is an even or odd number?, If it even then prints number is 
#even number else prints that number is odd number.

num = int(input("Enter the number: "))
if num % 2 == 0:
    print("Even number")
else:
    print("Odd number")
#W A P which takes two numbers from the user and prints below output:-
#     1. num1 is greater than num2 if num1 is greater than num2
#     2. num1 is smaller than num2 if num1 is smaller than num2
#     3. num1 is equal to num2 if num1 and num2 are equal

#Note:- 1. Do this problem using if - else 
#       2. Do this using ternary operator

a = int(input("Enter the 1st number"))
b = int(input("Enter the 2nd number"))
print ("Both numbers are equal" if a == b else "1st is greater than 2nd" if a > b else "2nd is greater than 1st")
#W A P which takes three numbers from the user and prints below output:-
#     1. num1 is greater than num2 and num3 if num1 is greater than num2 and num3
#     2. num2 is greater than num1 and num3 if num2 is greater than num1 and num3
#     3. num3 is greater than num1 and num2 if num3 is greater than num1 and num2

#Note:- 1. Do this problem using if - elif - else 
#       2. Do this using ternary operator

# a = a if a>b else b
#expr if cond1 else expr2 if cond2 else expr3

num1 = int(input("Enter the 1st number: "))
num2 = int(input("Enter the 2nd number: "))
num3 = int(input("Enter the 3rd number: "))

print("num1 is the greatest" if num1>num2 and num1>num3 else "num2 is the greatest" if num2>num1 and num2>num3 else "num3 is the greatest")<jupyter_output>Enter the 1st number: 1
Enter the 2nd number: 3
Enter the 3rd number: 2
num2 is the greatest<jupyter_text>Loops - for loop, while loop<jupyter_code>#Write a Python program to find the length of the my_str using loop:-

#Input:- 'Write a Python program to find the length of the my_str'
#Output:- 55

my_str = input("Enter the string")
length = 0
for i in my_str:
    if i == ' ':   ## need not be written if we want to consider space between 2 words
        continue
    else:
        length = length + 1
print(length)
#Write a Python program to find the total number of times letter 'p' is appeared in the below string using loop:-
    
#Input:- '<NAME> picked a peck of pickled peppers.\n'
#Output:- 9

input_str = '<NAME> picked a peck of pickled peppers.\n'
count = 0
for i in input_str:
    if i == 'p':
        count = count + 1

print(count)

#Write a Python Program, to print all the indexes of all occurences of letter 'p' appeared in the string using loop:-
    
#Input:- '<NAME> picked a peck of pickled peppers.'
#Output:- 
# 0
# 6
# 8
# 12
# 21
# 29
# 37
# 39
# 40

input_str = '<NAME> picked a peck of pickled peppers.\n'
count = 0
for i,j in enumerate(input_str):
    if j == 'p':
        print(i)
#Write a python program to find below output using loop:-

#Input:- '<NAME> picked a peck of pickled peppers.'
#Output:- ['peter', 'piper', 'picked', 'a', 'peck', 'of', 'pickled', 'peppers']

input_str = '<NAME> picked a peck of pickled peppers.'
output_str = ''
str_list = []
for i in input_str:
    if i == ' ' or i == '.':
        str_list.append(output_str)
        output_str = ''
    else:
        output_str += i
        
print(str_list)
#Write a python program to find below output using loop:-

#Input:- '<NAME> picked a peck of pickled peppers.'
#Output:- 'peppers pickled of peck a picked piper peter'

input_str = '<NAME> picked a peck of pickled peppers.'
output_str = ''
str_list = []
for i in input_str:
    if i == ' ' or i == '.':
        str_list.append(output_str)
        output_str = ''
    else:
        output_str += i
        
# print(str_list)
str_list = str_list[::-1]

new_str = ''
for i in str_list:
    new_str = new_str + i + ' '
    
print(new_str)
#Write a python program to find below output using loop:-

#Input:- '<NAME> picked a peck of pickled peppers.'
#Output:- '.sreppep delkcip fo kcep a dekcip repip retep'

input_str = '<NAME> picked a peck of pickled peppers.'
output_str = ''
#input_str = input_str[::-1]
#print(input_str) 

for i in input_str:
    output_str = i + output_str
print(output_str)
#Write a python program to find below output using loop:-

#Input:- '<NAME> picked a peck of pickled peppers.'
#Output:- 'retep repip dekcip a kcep fo delkcip sreppep'

input_str = '<NAME> picked a peck of pickled peppers.'
output_str = ''
new_str = ''

for i in input_str:
    if i == ' ' or i =='.':
        new_str = new_str + output_str[::-1] + " "
        output_str = ''
        
    else:
        output_str += i
print(new_str)
#Write a python program to find below output using loop:-

#Input:- '<NAME> picked a peck of pickled peppers.'
#Output:- '<NAME> Picked A Peck Of Pickled Peppers'
input_str = '<NAME> picked a peck of pickled peppers.'
output_str = ''
new_str = ''
for i in input_str:
    if i == ' ' or i == '.':
        output_str2 = output_str[0].upper() + output_str[1:]
        new_str = new_str + output_str2 + ' '
        output_str = ''
    else:
        output_str += i
        
print(new_str)
#Write a python program to find below output using loop:-

#Input:- '<NAME> Picked A Peck Of Pickled Peppers.'
#Output:- '<NAME> picked a peck of pickled peppers'

input_str = '<NAME> Picked A Peck Of Pickled Peppers.'
output_str = ''
new_str = ''
for i in input_str:
    if i == ' ' or i == '.':
        output_str2 = output_str[0].lower() + output_str[1:]
        new_str = new_str + output_str2 + ' '
        output_str = ''
    else:
        output_str += i

new_str2 = new_str[0].upper() + new_str[1:]
print(new_str2)
#Write a python program to implement index method using loop. If sub_str is found in my_str then it will print the index
# of first occurrence of first character of matching string in my_str:-

#Input:- my_str = '<NAME> Picked A Peck Of Pickled Peppers.', sub_str = 'Pickl'
#Output:- 29

input_str = '<NAME> Picked A Peck Of Pickled Peppers.'
sub_str = 'Pickl'

print(input_str.index(sub_str))  ## Used a builtin function
#Write a python program to implement replace method using loop. If sub_str is found in my_str then it will replace the first 
#occurrence of sub_str with new_str else it will will print sub_str not found:-

#Input:- my_str = '<NAME> Picked A Peck Of Pickled Peppers.', sub_str = 'Peck', new_str = 'Pack'
#Output:- '<NAME> Picked A Pack Of Pickled Peppers.'

input_str = '<NAME> Picked A Peck Of Pickled Peppers.'
sub_str = 'Peck'
new_str = 'Pack'
output_str = ''
str_list = []

for i in input_str:
    if i == ' ' or i == '.':
        str_list.append(output_str)
        output_str = ''
    else:
        output_str += i

i = 0
for item in str_list:
    if item == sub_str:
        str_list[i] = new_str
    i = i+1
        
# print(str_list)
my_str = ''
for ele in str_list:
    my_str = my_str + ele + ' '
    
print(my_str)

#Write a python program to find below output (implements rjust and ljust) using loop:-

#Input:- '<NAME> Picked A Peck Of Pickled Peppers.', sub_str = 'Peck', 
#Output:- '*********************Peck********************'

input_str = '<NAME> Picked A Peck Of Pickled Peppers.'
sub_str = 'Peck'

ind = input_str.index(sub_str)
# print(ind)
new_str = '*' * (ind) + sub_str + '*' * (len(input_str)-ind-len(sub_str))
print(new_str)
#Write a python program to find below output using loop:-

#Input:- 'This is Python class', sep = 'is', 
#Output:- ['This', 'is', 'Python class']

input_str = 'This is Python class'
sep = 'is'

str_list = input_str.split()
new_list = []
p_str = ''
n_str = ''
for i in str_list:
    if str_list.index(i) < str_list.index(sep):
        p_str = p_str + i + ' '
    if str_list.index(i) > str_list.index(sep):
        n_str = n_str + i + ' '
p_str2 = p_str.rstrip()
n_str2 = n_str.rstrip()
new_list.append(p_str2)
new_list.append(sep)
new_list.append(n_str2)

print(new_list)   

#Write a python program which takes one input string from user and encode it in below format:-
    # 1. #Input:- 'Python'
       #Output:- 'R{vjqp'
# str = input("Enter the string ")
# new_str = ''
# for i in str:
#     asc = ord(i)
#     asc = asc + 2
#     new_str = new_str + chr(asc)

# print(new_str)     

    # 2. #Input:- 'Python'
       #Output:- 'Rwvfql'
        
str = input("Enter the string ")
new_str = ''
count = 0
for i in str:
    asc = ord(i)
    if count % 2 == 0:
        asc = asc + 2
    else:
        asc = asc - 2
    
    new_str = new_str + chr(asc)
    count += 1

print(new_str)        
        
        
        
    # 3. #Input:- 'Python'    ## Output seems wrong here
       #Output:-  'R{vkfml'<jupyter_output>Enter the string Python
Rwvfql
{'fraction_non_alphanumeric': 0.12266411116435075, 'fraction_numerical': 0.02050790608528989, 'mean_word_length': 2.9969360398314824, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '73655', 'license': 'MIT', 'n_tokens_mistral': 3770, 'n_tokens_neox': 3580, 'n_words': 1403, 'path': 'Pranjal/Conditional_and_loop_assignment.ipynb', 'repo_name': 'Sureshkrishh/Practice-codes', 'size': '10560'}