| 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 = [] |
| temp = a |
| for i in range(a,a+10): |
| if temp == a: |
| num_set.append(temp) |
| else: |
| num_set.append(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) |
| |
|
|
| 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 any one:") |
| 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) |