Python Programming Exercises with Verified Answers, Exams of Nursing

A collection of python programming exercises with verified answers, covering fundamental concepts such as inheritance, data types, string manipulation, loops, functions, and modules. It is a valuable resource for students learning python, offering practical examples and solutions to reinforce their understanding.

Typology: Exams

2023/2024

Available from 01/15/2025

Toperthetop
Toperthetop 🇬🇧

3

(6)

28K documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Comp 348 (questions with verified
answers) already passed
Inheritance: how do we actually create subclasses in Python - correct answer ✔✔class Foo(Baz):
x = 43
__init__(self):
Baz__init__(self)
self.thing = "thing"
get_x(self):
return self.x
What are some interpreted languages - correct answer ✔✔Python, Javascript
What are some compiled languages - correct answer ✔✔C, C++, Clojure, Earlang
What are languages are both compiled and interpreted - correct answer ✔✔Java
What languages support static typing - correct answer ✔✔C, C++, Java
What languages support dynamic typing - correct answer ✔✔Python, Erlang, JavaScript, PHP
How do you quit python interpreter - correct answer ✔✔CTRL-D or quit()
How are python integer stored - correct answer ✔✔in a C signed long int.
How are python floating point values stored - correct answer ✔✔C double
pf3
pf4
pf5

Partial preview of the text

Download Python Programming Exercises with Verified Answers and more Exams Nursing in PDF only on Docsity!

Comp 348 (questions with verified

answers) already passed

Inheritance: how do we actually create subclasses in Python - correct answer ✔✔class Foo(Baz): x = 43 init(self): Baz__init__(self) self.thing = "thing" get_x(self): return self.x What are some interpreted languages - correct answer ✔✔Python, Javascript What are some compiled languages - correct answer ✔✔C, C++, Clojure, Earlang What are languages are both compiled and interpreted - correct answer ✔✔Java What languages support static typing - correct answer ✔✔C, C++, Java What languages support dynamic typing - correct answer ✔✔Python, Erlang, JavaScript, PHP How do you quit python interpreter - correct answer ✔✔CTRL-D or quit() How are python integer stored - correct answer ✔✔in a C signed long int. How are python floating point values stored - correct answer ✔✔C double

Python turn off escape characters - correct answer ✔✔Raw Strings with r"the string" How to access lass char of string in Python - correct answer ✔✔s1 = "bigdog" print s1[-1] Python slices format - correct answer ✔✔inclusive/exclusive. x[2:4] means x[2] to x[3] s1 = "bigdog" s1[2:4] s1[2:] s1[:4] s1[-2:] s1[2:-2] s1[2:2] s1[2:44] - correct answer ✔✔s1 = "bigdog" s1[2:4] # gd s1[2:] # gdog s1[:4] # bigd s1[-2:] # og s1[2:-2] # gd s1[2:2] # s1[2:44] # gdog Name 3 sequences in Python - correct answer ✔✔string, list, tuples In Python, can any variable be used with FOR loop - correct answer ✔✔No it has to be a sequence Python what are the bounds of this range function range (4, 20, 5) - correct answer ✔✔# 4 to 19, by 5's

Python are global variables visible everywhere - correct answer ✔✔visible throughout the module but not outside the module Python how do you see the interpreter records names - correct answer ✔✔dir()

  • List names from the current module
  • dir(module) List names from an imported module Python what is name - correct answer ✔✔a string value that holds the name of the module If the module represents the "starting" module for the app, the name is actually set to "main What is init.py - correct answer ✔✔To indicate to the interpreter that the folders do in fact represent a package, each (sub)package must include a init.py file at the root level.
  • The file can in fact be empty
  • It can contain some package level initialization code that will be run the first time the package is accessed.
  • It can also contain a list of the modules that should be imported when the "from package import *" syntax is used, as indicated below. all = ["foo", "bar"]

Python does objects have their own variables - correct answer ✔✔So ANY changes made to a variable defined outside of the method definitions affects ALL such objects. Python what is init - correct answer ✔✔If init is present, it becomes the default constructor for an object. class Foo: x = 43 init(self): self.stuff = "stuff" get_x(self): print self. In this case, a new variable called stuff will be created and added to the object instance

  • If we instantiate n objects, each of the n objects will now have its own local version of stuff What about constructors - correct answer ✔✔one _init method per class (default) You can certainly add additional constructors.
  • However, these will use standard method syntax and naming conventions.
  • init1(), init2(), init_float()
  • You can also use method defaults to provide (or not provide) additonal arguments
  • init(self, person=None) Constructors can call other constructors