Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Presentatie

Learning Journal 3

Beoordeling
-
Verkocht
-
Pagina's
5
Geüpload op
02-05-2020
Geschreven in
2019/2020

Presentation of 5 pages for the course CS 1101 at university of the people (Learning Journal)

Instelling
Vak

Voorbeeld van de inhoud

1. Program:
def countdown (n):
if n <= 0:
print('Blastoff !')
else:
print(n)
countdown(n-1)


def countup(n):
if n >= 0:
print('Blastoff !')
else:
print(n)
countup(n+1)


n = int(input('Enter Number'))
if n > 0:
(countdown(n))
elif n < 0:
(countup(n))
else:
(countdown(0))




Output for Negative Input:
Enter Number-5
-5
-4
-3
-2
-1
Blastoff !
Output for Positive Input:
Enter Number5
5
4
3
2
1

, Blastoff !

Output for Zero input:
Enter Number0
Blastoff !
Explanation:
In this program I chose countdown as a function call for input of zero because I think
zero is very close to the countdown function as all numbers which are greater than zero
eventually decrease when countdown function is called.

2. Program:
>>> x = 12
>>> y = 6
>>> z = x * y * math.pi

Output:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
z = x * y * math.pi
NameError: name 'math' is not defined

Explanation:
In this program we encounter with runtime error known as NameError which tells us that
we didn’t define math in the program so python doesn’t know what to do with math and
it gives us runtime error. In the program math was supposed to be imported module to
solve mathematical functions but we didn’t import or define it so python can’t handle
such operations.
Solution:
The solution to solve this runtime error is to import math module in the program using
import math code so that it can handle with mathematical functions of any kind like pi in
this program.

References:
1. Chained conditional: In python we often come across problems which involve many
conditions and we only want one perfect answer from these possibilities. Chained
conditional allows us to add more than two conditions or alternatives which are called
branches and only that branch is executed which equals to the desire outcome ‘True’.
Example:
def relation(x,y):
if x == 'James mark' and y == 'Sam mark':
print(x, y,'are brothers')
elif x == 'James mark' and y == 'William will':
print(x, y, 'are cousins')

Geschreven voor

Instelling
Studie
Vak

Documentinformatie

Geüpload op
2 mei 2020
Aantal pagina's
5
Geschreven in
2019/2020
Type
PRESENTATIE
Persoon
Onbekend

Onderwerpen

$7.17
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
usamamalik8106

Maak kennis met de verkoper

Seller avatar
usamamalik8106 Artesis Hogeschool Antwerpen
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
6 jaar
Aantal volgers
0
Documenten
6
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen