Difference between revisions of "User:Praveer-mathur-9f3d@uni-bonn.de"

From HPC Wiki
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Short Quiz: Variable Assignment === <!--T:5--
+
[[/intro-to-programming-with-python]]
  
What values do the two variables "mass" and "age" have in the following lines?
+
[[/python-on-hpc]]
  
{{hidden begin
+
[[/version-control-with-git]]
|title = <code>mass = 47.5 <br> print(mass)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>47.5</code>
 
</quiz>
 
{{hidden end}}
 
  
{{hidden begin
+
[[/intro-to-working-on-hpc-clusters]]
|title = <code>age = 122 <br> print(mass, age)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>47.5 122</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>mass = mass * 2.0 <br> print(mass, age)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>95.0 122</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>age = age - 20 <br> print(mass, age)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>95.0 102</code>
 
</quiz>
 
{{hidden end}}
 
 
 
=== Short Quiz: Data Types === <!--T:5-->
 
 
 
{{hidden begin
 
|title = <code>planet = 'Earth'</code> <br> What datatype does the variable planet have?
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
- Integer
 
|| Explanation: Wrong
 
+ String
 
|| Explanation: Correct
 
- Boolean
 
|| Explanation: Wrong
 
- Float
 
|| Explanation: Wrong
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>apples = 5</code> <br> What datatype does the variable apples have?
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+ Integer
 
|| Explanation: Correct
 
- String
 
|| Explanation: Wrong
 
- Boolean
 
|| Explanation: Wrong
 
- Float
 
|| Explanation: Wrong
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>distance = 10.5</code> <br> What datatype does the variable distance have?
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
- Integer
 
|| Explanation: Wrong
 
- String
 
|| Explanation: Wrong
 
- Boolean
 
|| Explanation: Wrong
 
+ Float
 
|| Explanation: Correct
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>false = 7 > 2</code> <br> What datatype does the variable false have?
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
- Integer
 
|| Explanation: Wrong
 
- String
 
|| Explanation: Wrong
 
+ Boolean
 
|| Explanation: Correct
 
- Float
 
|| Explanation: Wrong
 
</quiz>
 
{{hidden end}}
 
 
 
=== Short Quiz: Boolean Operations === <!--T:5-->
 
 
 
<code>var1 = True <br> var2 = False</code>
 
What is the value of each variable after each of the following print statements?
 
 
 
{{hidden begin
 
|title = <code>print(var1, var2)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>True False</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>var2 = var1 or var2 <br> print(var1, var2)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>True True</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>var1 = var1 and not var2 <br> print(var1, var2)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>False True</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>var1 = not(var1 and not var1) <br> print(var1, var2)</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>True True</code>
 
</quiz>
 
{{hidden end}}
 
 
 
=== Short Quiz: String Concatenation === <!--T:5-->
 
 
 
<code>str1 = "Uni" <br> str2 = "Bonn" <br> str3 = str2 + str1 <br> str4 = str1 * 3</code>
 
 
 
{{hidden begin
 
|title = What output do you expect after doing <code>print(str3)</code>?
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>BonnUni</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = What output do you expect after doing <code>print(str4)</code>?
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>UniUniUni</code>
 
</quiz>
 
{{hidden end}}
 
 
 
=== Short Quiz: Containers === <!--T:5-->
 
 
 
Read the following code:
 
 
 
<code>uni = {"departments": ["physics", "chemistry"], <br> "employees": 4000, <br> "campuses": ("Poppelsdorf", "Endenich"),}</code>
 
 
 
What do the following lines print? Keep in mind that the lines could also give an error output.
 
 
 
{{hidden begin
 
|title = <code>print(uni[0])</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>KeyError: 0</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>print(uni["departments"][0]</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>physics</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>print(uni["employees"] = 5000</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| Nothing
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>print(uni["campuses"][0] = "Innenstadt"</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>TypeError: 'tuple' object does not support item assignment</code>
 
</quiz>
 
{{hidden end}}
 
 
 
{{hidden begin
 
|title = <code>print(uni["campuses"][0]</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+  Click and submit to see the answer
 
|| <code>Poppelsdorf</code>
 
</quiz>
 
{{hidden end}}
 
 
 
=== Short Quiz: Understanding if Statements === <!--T:5-->
 
 
 
Which of the following statements would get printed?
 
 
 
{{hidden begin
 
|title = <code>if '': <br> print('empty string is true')</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
- Yes
 
|| Explanation: Wrong
 
+ No
 
|| Explanation: Correct
 
</quiz>
 
{{hidden end}}
 
 
 
 
 
{{hidden begin
 
|title = <code>if 'word': <br> print('word is true')</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+ Yes
 
|| Explanation: Correct
 
- No
 
|| Explanation: Wrong
 
</quiz>
 
{{hidden end}}
 
 
 
 
 
{{hidden begin
 
|title = <code>if []: <br> print('empty list is true')</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
- Yes
 
|| Explanation: Wrong
 
+ No
 
|| Explanation: Correct
 
</quiz>
 
{{hidden end}}
 
 
 
 
 
{{hidden begin
 
|title = <code>if [1, 2, 3]: <br> print('non-empty list is true')</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+ Yes
 
|| Explanation: Correct
 
- No
 
|| Explanation: Wrong
 
</quiz>
 
{{hidden end}}
 
 
 
 
 
{{hidden begin
 
|title = <code>if 0: <br> print('zero is true')</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
- Yes
 
|| Explanation: Wrong
 
+ No
 
|| Explanation: Correct
 
</quiz>
 
{{hidden end}}
 
 
 
 
 
{{hidden begin
 
|title = <code>if 1: <br> print('one is true')</code>
 
}}
 
<quiz display=simple>
 
{
 
|type="()"}
 
+ Yes
 
|| Explanation: Correct
 
- No
 
|| Explanation: Wrong
 
</quiz>
 
{{hidden end}}
 

Latest revision as of 16:35, 18 March 2026