File size: 7,156 Bytes
18b15b7 26b1918 18b15b7 cce4c75 18b15b7 cce4c75 18b15b7 7f44d6e 487a612 d23feda 7f44d6e fe3cdaf 32ff372 7f44d6e fe3cdaf 32ff372 191e342 7f44d6e e7252d8 26b1918 7f44d6e 56a1636 2a8ca9e 56a1636 6906103 56a1636 3b0f355 d0f693f 3b0f355 d0f693f 143268a ec75a43 a9ba65c a8a01b5 a9ba65c f599585 a8a01b5 a9ba65c 1d2b3c5 143268a 1df6842 9299f66 b6029e2 18b15b7 cfedfbb cfa56cd 1df6842 d37b359 7f44d6e cfa56cd 7f44d6e e7252d8 cfa56cd e7252d8 26b1918 26c1e03 56a1636 6906103 91ff767 6906103 d0f693f 146350c 143268a d0f693f 3b0f355 143268a 93f91da 1d2b3c5 6906103 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
import streamlit as st
description1 = "Given two integer numbers, return their product only if the product is equal to or lower than 1000. Otherwise, return their sum."
description2 = "Iterate the first 10 numbers, and in each iteration, returns the sum of the current and previous number."
description3 = "Display characters that are present at an even index number from the provided string."
description4 = "Remove the characters from a string starting from zero up to n and returns a new string."
description5 = "Returns the number of times a substring is present in the provided string."
description6 = "Checks if a number is Palindrom or Not."
description7 = "Given two list of numbers, returns a new list such that the new list contains odd numbers from the first list and even numbers from the second list."
description8 = "Returns multiplication table of the provided number range."
description9 = "Returns an integer value of base raises to the power of exponent."
def sum_of_two(a,b):
prod = a*b
sum1 = a+b
if prod <= 1000 :
return(prod)
else:
return(sum1)
def start_iteration(a):
num_set = '''
Showning current and previous number sum in a range(10): \n'''
temp = a
for i in range(a,a+10):
if temp == a:
num_set = num_set +f'''
Current Number {temp} Previous Number 0 Sum: {temp} '''
else:
num_set = num_set + f'''
Current Number {temp} Previous Number {temp-1} Sum: {temp+temp-1} '''
temp = temp + 1
return(num_set)
def even_index(str1):
str_lst = []
for i in range(len(str1)):
if i % 2 == 0 :
str_lst.append(str1[i])
return(str_lst)
def change_str(str2,num2):
new_srt = ""
for i in range(num2,len(str2)):
new_srt = new_srt + str2[i]
return new_srt
def str_count(str3,sub_str):
new_str3 = str3.lower()
new_sub_str = sub_str.lower()
x = new_str3.count(new_sub_str)
return x
def check_palin(check_num):
num_str = str(check_num)
if num_str == num_str[::-1] :
return("Palindrom")
else:
return("Not Palindrom")
def create_new(num_str1,num_str2):
fin_lst = []
num_lst1 = num_str1.split()
num_lst2 = num_str2.split()
for x in num_lst1:
if int(x) % 2 == 1:
fin_lst.append(int(x))
for y in num_lst2:
if int(y) % 2 == 0:
fin_lst.append(int(y))
return(fin_lst)
def create_tbl(tbl1,tbl2):
list_of_tbl = []
if tbl1<tbl2:
for i in range(tbl1,tbl2+1):
table_lst = []
for j in range(1,11):
table_lst.append(j*i)
list_of_tbl.append(table_lst)
return(list_of_tbl)
elif tbl2<tbl1:
for i in range(tbl2,tbl1+1):
table_lst = []
for j in range(1,11):
table_lst.append(j*i)
list_of_tbl.append(table_lst)
return(list_of_tbl)
else:
for j in range(1,11):
list_of_tbl.append(tbl2*j)
return(list_of_tbl)
def find_exp(base1,exp1):
if exp1 < 0 :
exp1 = exp1 * (-1)
return base1**exp1
st.markdown("<h3 style='text-align:center; font-size:24px;'>Mathematical and String Operations</h3>", unsafe_allow_html=True)
st.write("---")
radio_bar = st.sidebar.radio(options=[description1, description2, description3, description4, description5, description6, description7, description8, description9], label="Select from the below mentioned operations:")
if radio_bar == description1:
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description1+"</h6>", unsafe_allow_html=True)
first_num = st.number_input(label="Enter First Number:",value=0)
second_num = st.number_input(label="Enter Second Number:",value=0)
all_data = st.button("Calculate result")
if all_data:
result = sum_of_two(first_num,second_num)
st.success(result)
if radio_bar == description2 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description2+"</h6>", unsafe_allow_html=True)
first_num = st.number_input(label="Enter Starting Number:",value=0)
all_data = st.button("Show result")
if all_data:
result = start_iteration(first_num)
st.success(result)
if radio_bar == description3 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description3+"</h6>", unsafe_allow_html=True)
str1 = st.text_input(label="Enter the string:",value="")
all_data = st.button("Show result")
if all_data:
result = even_index(str1)
st.success(result)
if radio_bar == description4 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description4+"</h6>", unsafe_allow_html=True)
str2 = st.text_input(label="Enter the string:",value="")
char_num = st.number_input(label="Number of characters to remove:",value=0)
all_data = st.button("Show result")
if all_data:
result = change_str(str2,char_num)
st.success(result)
if radio_bar == description5 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description5+"</h6>", unsafe_allow_html=True)
str3 = st.text_input(label="Enter the string:",value="")
sub_str= st.text_input(label="Enter the sub-string:",value="")
all_data = st.button("Show result")
if all_data:
result = str_count(str3,sub_str)
st.success(f"The sub-string is present {result} times in the string.")
if radio_bar == description6 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description6+"</h6>", unsafe_allow_html=True)
check_num = st.number_input(label="Enter Number:",value=0)
all_data = st.button("Check")
if all_data:
result = check_palin(check_num)
st.success(result)
if radio_bar == description7 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description7+"</h6>", unsafe_allow_html=True)
num_str1 = st.text_input(label="Enter the numbers of first list and separate each number by single space(' '):",value=0)
num_str2 = st.text_input(label="Enter the numbers of second list and separate each number by single space(' '):",value=0)
all_data = st.button("Show Result")
if all_data:
result = create_new(num_str1,num_str2)
st.success(result)
if radio_bar == description8 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description8+"</h6>", unsafe_allow_html=True)
start_num8 = st.number_input(label="Enter start Number:",value=0)
end_num8 = st.number_input(label="Enter end Number:",value=0)
all_data = st.button("Show Result")
if all_data:
result = create_tbl(start_num8,end_num8)
st.success(result)
if radio_bar == description9 :
st.markdown("<h6 style='text-align:center; font-size:16px;'>"+description9+"</h6>", unsafe_allow_html=True)
base_num = st.number_input(label="Enter Base Number:",value=0)
exp_num = st.number_input(label="Enter Exponent:",value=0)
all_data = st.button("Calculate")
if all_data:
result = find_exp(base_num,exp_num)
st.success(result) |