So, we have learned how to use user defined input by using the input function. Now, imagine I walk into a restaurant or let's say shop where there is a discount of 10% which means if you buy something for 100 rupees, you actually got to pay only 90 rupees. Now, if you buy something for 150, you going to pay only 135 rupees. So, you will get a discount of 10% which means whatever is the price you should multiply by point nine. So, now, let us write the program, which takes as input the cost and then tells you the price after discount, basically, it must simply multiply by point nine and then give you the answer. So, now, how do I go about this, let me teach you something.
So, here I will write C is equal to input word sorry I to run the quotes. So, what is the cost? Now, whenever I run this, it will ask for me the cost. So suppose I'm right here 300 enter. So 300 is the cost. Now, here, I want to calculate the discount discounted price.
So, what I have to do is suppose a D is a variable and here I write C into point nine. So, will it give me the result because now the value of c is 300. So will it give me the result? Yes check. No print D. Now run it. See I got an error.
Why? I have input 300. Whenever it asked for the cost, even then it says cannot be Multiply sequence by non integer of type float. That means, whenever you will input something like this in the by using the input function, it will always input as a string. So, anything you enter by using the input function will input as a string. Now, you cannot perform an arithmetic operation using a string on any string or any character value you cannot perform any arithmetic operation.
So, it is showing you this error now, what we can do is we can convert this particular value to integer to a number. Now how to convert this C So, first the value of c is stored as 300 but 300 is stored as a stream. Now here I'll convert this 300 or this C into an integer How will shall convert it So, d is equal to write int, and then within bracket write the variable name you want to convert. So, here my variable name is C, so and write C. Now, I will write suppose price discounted price. So, price is equal to T into point nine. Now print this price, see, if you get the result or not, so, print it see it perform perfectly.
So, it first convert the value of 300 from string to integer, then perform the operation that have been given and then it printed the value of price. So, let me write the program for this. So, first I write print, then here I write Hello let us calculate discounted price. Come to the next line now provide the value that is input what will be the price so I'm right here enter the price again now whatever price you will input it will be stored as string. So first my first task will be to convert that particular string to an integer or to a number. So, here I'll write d is equal to, int, int is a function to convert your string to integer.
So what why do I want to convert the value of c i want to convert to integer so I've written in C then I'm right price is equal to 0.9. into D why I've written D because now the converted value that is converted value of C from string to integer is now stored in D. So, I have written d over here and now I write print the cost of the product is give a comma and write price here now, run this code. So, it will first ask see it first writes Hello let us calculate the discounted price. Now, enter the price. So, what is the price just enter it over year suppose my MRP of the product is say hundred thousand okay. So, now, after entering thousand, just press enter, so, it will give you the discounted price. So, the cost of the product is 900.
So, now, you got the cost of the product after discount. So, what I got is it first take the value of c whatever I will input and then it will convert that particular value to integer And it will store it to D and then again it will perform this operation on D and it will print the result in this way. Now, if your value changed, so, now if I run this particular code again what will it will do? It will again ask me the price Now, suppose my prices 2000 now, please enter it, see what it gives, it gives Hello let us calculate the discounted price, enter the price I've written 2000 it converted the string to integer and then it performed the operation and then it calculated the discounted price and what is the discounted price it is 1800. So, in this way, whatever be the value is it will calculate the discounted price and we'll show you the result.
So, if you want to run this code again, so, just run it provides the value over here. beat any value present And it will give you the discounted price. So, in this way we have created a program where we can calculate a discounted price of any amount. Now, suppose if the discount changes, suppose I am giving a discount of 10%. Now, suppose the shop is giving the discount of 20%. So, then what you can do, you can just copy this code, paste it over here and just change the discounted rate over here Here I've given 10% discount.
So, here I will write 0.84 20% 0.754 25% 0.854 15%. So, suppose Here I am to give 80% is 20% discount, so I've written 0.8 into T So, just run the score, provide the amount omp and presenter See, it gives me 20% is gone and the value is now 1600. So by changing a little potion or a little value of the discount, or the value of the amount, the whole program will execute accordingly. So today we have learned how to create a discounted value for a given amount. So I'll be ending my video over here. See you the next video.
Thank you