100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
Python Basics Test Questions with All Answers €12,50   In winkelwagen

Tentamen (uitwerkingen)

Python Basics Test Questions with All Answers

 10 keer bekeken  0 keer verkocht
  • Vak
  • Python Basics
  • Instelling
  • Python Basics

Python Basics Test Questions with All Answers Use two argument specifiers to print that the "name" is an "age" of 20. - Answer-name = "Tim" age = 20 print("%s is %d years old." % (name, age)) For list *mylist* of [1, 2, 3], print "A list:" followed by the list, using an argument specifier. -...

[Meer zien]

Voorbeeld 2 van de 7  pagina's

  • 12 augustus 2024
  • 7
  • 2024/2025
  • Tentamen (uitwerkingen)
  • Vragen en antwoorden
  • Python Basics
  • Python Basics
avatar-seller
Python Basics Test Questions with
All Answers

Use two argument specifiers to print that the "name" is an "age" of 20. - Answer-name =
"Tim"
age = 20
print("%s is %d years old." % (name, age))

For list *mylist* of [1, 2, 3], print "A list:" followed by the list, using an argument specifier.
- Answer-mylist = [1, 2, 3]
print("A list: %s" % mylist)

Four basic argument specifiers: - Answer-1. %s - String

2. %d - Integers

3a. %f - Floating point numbers
3b. %.<numberofdigits>f - Floating point numbers with a fixed amount of digits to the
right of the dot.

4a. %x - Lowercase hexidecimal integer
4b. %X - Uppercase hexidecimal integer

Exercise:

-Write a format string which prints out the data using the following syntax:
*Hello John Doe. Your current balance is $53.44*

-Code given:
data = ("John", "Doe", 53.44)
format_string = ?

print(format_string % data) - Answer-Answer:

format_string = "Hello, %s %s. Your current balance is $%s"

Print the length of variable astring, "Hello world!" - Answer-astring = "Hello world!"

print(len(astring))

, Find the location of the letter o in the variable astring, "Hello world!" - Answer-astring =
"Hello world!"

print(astring.index("o"))

Count how many times l appears in the variable astring, "Hello world!" - Answer-astring
= "Hello world!"

print(astring.count("l"))

Print a slice of the variable astring, "Hello world!", starting at index 3 and ending at index
6. - Answer-astring = "Hello world!"

print(astring[3:7])

Print variable astring, "Hello world!", backwards - Answer-astring = "Hello world!"

print(astring[::-1])

Print variable astring, "Hello world!", in all lowercase vs. all uppercase - Answer-astring
= "Hello world!"

All lowercase:
print(astring.lower())

All uppercase:
print(astring.upper())

Print a slice of the variable astring, "Hello world!", starting at index 3 and ending at index
6, skipping every other letter (increment of 2) - Answer-astring = "Hello world!"

print(astring[3:7:2])

Print true or false for the variable astring, "Hello world!", checking if it starts with "Hello"
and ends with "asdfghjkl" - Answer-astring = "Hello world!"

print(astring.startswith("Hello"))

print(astring.endswith("asdfghjkl"))

Split the two terms in the variable astring, "Hello world!" - Answer-astring = "Hello
world!"

afewwords = astring.split(" ")

Boolean example with x = 2 and comparisons to 2, 3, and less than 3 - Answer-x = 2

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper Perfectscorer. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €12,50. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 80562 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€12,50
  • (0)
  Kopen