-
Notifications
You must be signed in to change notification settings - Fork 0
ICP 1
In this ICP, we have learnt about what is python, where it is being used, applications and industries using it. Also about its development environment, basic operators and statements used which are used while programming in python.
Below are softwares used:
-
Python version 3
-
Pycharm
-
Anaconda
-
Github Desktop.
Input the string “Python” as a list of characters from console, delete at least 2 characters, reverse the resultant string, and print it.
For the above case, python code is written in such a way that:
(a) Python word is declared as string to a variable a_string
(b) First the character “h” is deleted from the string, using replace function. In this function character “h” is replaced with empty character. The output string “pyton” is stored in variable a_string.
(c) In the next step, another character “o” is removed from a_string, using the same replace function as in above step. The resultant output string is “pytn” is stored in another variable b_string.
(d) Now print function “print(b_string[::-1])” is used to reverse the string “pytn” as “ntyp”
(e) Hence the resultant output is shown as “ntyp”
Take two numbers from user and perform arithmetic operations on them.
(a) To take two numbers from user, num1 and num2 are assigned as inputs integers and values are stored in num1 and num2.
(b) The basic arithmetic operations “addition”, “subtraction”, “multiplication”, “division” are performed on the two strings using “ +, - , * , / ” operators.
(c) Those values are stored in the variables and printed using the print function.
(d) Hence the resultant output is displayed on the console.
3.Write a program that accepts a sentence and replace each occurrence of ‘python’ with ‘pythons’ without using regex
For the above case instead of using “regex” regular expression, replace function is used.
(a) To take the sentence from user, input function is used and the stored in a variable “s”.
(b) Print function is used to print the original sentence given by the user.
(c) Replace function is used to replace the word python with pythons. And the resultant string is stored in a variable “r”.
(d) Print function prints the modified sentence.
(e) If the user enters the sentence containing the word “Python” in it, then the replace function is executed in order to replace the word “Python” with “Pythons”.
(f) If the user enters a sentence without the word “Python” then it prints only the original sentence given by user. Since there is no word “Python” to replace.
(g) Hence the resultant output is displayed.