Basic User Input

How the input function works in Python :

The Input is nothing but some value from a system or user.

https://pynative.com/python-input-function-get-user-input/

When input() function executes program flow will be stopped until the user has given an input.

input(): Whatever you enter as input, input function convert it into a string. If you enter an integer value still input() function convert it into a string. You need to explicitly convert it into an integer in your code using typecasting.

  • Use the prompt parameter to write a message before the input(‚Give me the first number: ‚)

In most cases, the corresponding cast-operator is immediately applied to the result string of input in order to obtain the data type required (like integer, float etc.) for further processing:

age = int(input(‚Your age: ‚))

Printing for your success

No this blog entry is not about how to use a printer. It is about how to use Basic Output with the print statement. The print function serves to correspond with the outside world.

The print function prints any number of values separated by commas. If an object isn’t a string, then print() converts it to an appropriate string representation displaying it. In the output, the values are separated by blanks by default. If you don’t want a separation by spaces, it is necessary to convert for example an integer value into a string on your own (see picture below).

Basic Types in Python…

… sounds boring, is boring – but even though it is important to know them.

Variables reserve memory locations to store values depending on data type:

Numerical types:

  • int (signed integers)
  • long (long integers, they can also be represented in octal and hexadecimal)
  • float (floating point real values)
  • complex (complex numbers)

Strings str are mostly used for saving word, sentences or texts. Subsets of strings can be taken using the slice operator ([ ]) (indexes starting at 0, ending at string length -1)

Boolean values bool can be true or false and are used in Logical operations.

There are many more data types in Python but for the time the mentioned are sufficient.

Fun With Numbers

First assignment was to perform simple arithmetic operations.

To be aware of:

  • Integer ≠ String
  • x % y Modulo Operator
  • x/y Divisor can be float value
  • x//y Divisor is only integer value

Who am I?

Hey, my Name is Niklas, I am 21 years old and I am studying Industrial Engineering. Right now I am spending one semester abroad at Tec de Monterrey in Guadalajara, Mexico.

Why did I create this blog?

  • Because I want to share with you my experiences while learning programming with Python.

Why do I want to learn programming with Python?

  • Because I think it is essential to learn the basics of programming in a digitzed world.

I am happy if you are interested in following me during the next months. I hope that I can inspire you to learn programming as well.

Erstelle eine Website wie diese mit WordPress.com
Jetzt starten