# Connexions

You are here: Home » Content » Output (Umonya)

### Recently Viewed

This feature requires Javascript to be enabled.

# Output (Umonya)

Module by: Neil Muller. E-mail the author

When running code in a script, we no longer see the result of operations immediately. We need to tell python to display the results. This is known as output.

We tell python to display output by using the print function. print('Something') will print the string 'Something'

name=input('What is your name ? ')
print('Hello')
print('Your name is ' + name)
number=float(input('Give me a number, ' + name + ' '))
print('The number is ' + str(number))
print('3 times this number is ' + str(3*number))
print('Goodbye ' + Bob)

What is your name ? Bob
Hello
Give me a number, Bob 1.5
The number is 1.5
3 times this number is 4.5
Goodbye Bob



Script with output

The print('Hello') line just prints the string 'Hello'. print('Your name is ' + name) prints the string that results from "'Your name is ' + name"

## Exercise 1

What will print('Hello ' + 'Goodbye') display?

### Solution

'Hello Goodbye'

print('The number is ' + str(number)) converts number to a string, and then displays the result of adding that to the string 'The number is '

## Exercise 2

Write a script that asks for a name and then displays "Hello " + name. i.e, so if Bob types his name, it answers "Hello Bob".

### Solution


name=input('What is your name ? ')
print('Hello ' + name)


## Exercise 3

Write a script that asks for a number and then displays 10 times the number, 5 times the number and 2 times the number.

### Solution

number=float(input('Enter a number : '))
print('10 times the number is ' + str(10*number))
print('5 times the number is ' + str(5*number))
print('2 times the number is ' + str(2*number))


## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks