| 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) |