Asking a question
pucho(sawal) ("ask") shows the question and gives back the next line of input as text. On this site, input comes from the Input box under the editor: each line of that box answers one pucho, in order. When the lines run out, pucho returns khali, so your program can notice there is nothing more to read.
Answers are text — convert them
Whatever the user types arrives as text, even if it looks like a number. Before doing maths, wrap it in sankhya(). Forgetting this is the most common input bug: "10" + 5 would print 105.
Reading until the input ends
Because pucho returns khali when there is nothing left, a jab_tak loop can read any number of lines. Check for khali before using the value.
Mini project: report card
Time to combine variables, conditions, loops, functions, lists and input. The program below reads a student's name and marks, then prints the total, the percentage and a grade. Change the input box and run it again — then try adding a "highest subject" line on your own.
Expected output
Press Run to try it
? Student ka naam?? Marks?? Marks?? Marks?? Marks?Report card: PriyaTotal: 247 / 300Percentage: 82Grade: A
Practice exercise
Read two lines of input — a name and an age — and print <name> agle saal <age + 1> ka hoga. With the input below the output is Dev agle saal 25 ka hoga.
Expected output
Dev agle saal 25 ka hoga
Test input (fed to pucho)
Dev 24
Show solution
rakho naam = pucho("Naam?");
rakho umar = sankhya(pucho("Umar?"));
bol(naam, "agle saal", umar + 1, "ka hoga");