top of page
Search

Step 3 - Input and Output

  • Writer: Coding GP Team Project
    Coding GP Team Project
  • Oct 14, 2020
  • 2 min read



This is the really interesting part of the project, we learn to Input and Output! As you saw in the previous lines of code, we use print statement, to print something to the console, it's as simple as that! We can print either a variable, a string or both in the program! Here is an example:

The syntax is:


print("What do you want to print")
print(variable) # You have to declare the variable first

projectName = "Code2Learn"
#You can change both of the variable strings to your own!
name = "Adeetya"
print("Welcome to our Program")
print("Our project's name is", projectName,"and my name is",name)

We use the comma (",") to inform the program that we have a variable as well as a string together. We can also use "+" for string concatenation (Not needed right now). Let's run the above program in our IDEs.


Input is simply taking an input from the user through the console, and then responding accordingly. You need to store that input, and you will store it in a variable. Don't worry, python automatically decides the data type you need for your variable. All you need to do is name it, and call the input function! You can also put a string inside your input, to explain to the user what it does. The syntax for input is:

variable = input("Tell the user what to input")

Here is an example!

name = input("What is your name?: ")
age = input("What is your age?: ")
print("Hello",name,"! My name is Python")
print("Oh,so you are",age,"years old? Well, I am 29 years old!"))

Let's run it:


And that's it! You learned how to input and output!


Click here to move on to the next step!


 
 
 

Comments


©2020 by Code2Learn

bottom of page