Assignment
Launch Blender, and switch to Scripting view. In the Console, complete each of the following tasks:
I. Set the variables:
s = "Hello"
t = "World"
Then, enter the expression to complete each of the following tasks. For each task:
• evaluate the Python expression
• write the result
• explain how the expression produced the result
len(s) + len(t)
Result:
Explanation:
s[1:2]
Result:
Explanation:
s[len(s)//2:len(s)]
Result:
Explanation:
s + t
Result:
Explanation:
t + s
Result:
Explanation:
II. Set the variables:
str = "Gateway"
i = 2
j = 4
Write each of the following as a Python, then evaluate the expression and write down the result.
Set first to the substring of str from the start of str to the last position before i.
Python expression:
Result:
Set middle to the substring of str from positions i + 1 to j - 1.
Python expression:
Result:
Set last to the substring of str from position j + 1 to the end of str.
Python expression:
Result:
Concatenate the following five strings: first, the string containing just the character at position j, middle, the string containing just the character at position i, and last.
Python expression:
Result:
III. Write a Python expression that is an example of each of the following tasks. Test your expression on the string variable str:
str = "Programming"
Get the first character of a string.
Get the last character of a string.
Remove the first character of a string.
Remove the last character of a string.
VI. Write a Python expression (or script) that, given the variable inputStr, set as:
inputStr = "The quick brown fox jumps over the lazy dog"
uses the Python string operators to set the variable outputStr as:
outputStr = "Tempus fugit"
V. Write a Python script that, assuming the variable dayNum is set to a number from 1 to 7, displays the name of the corresponding weekday, assuming Sunday is dayNum 1, and Saturday is dayNum 7.
VI. Set the variable numberList to a list of numbers (e.g., 1, 4, 9, 16, 9, 7, 4, 9, 11). Then, write a Python script that rotates the list by 1 number (e.g., 4, 9, 16, 9, 7, 4, 9, 11, 1).
Then, re-write the script so that it rotates the list by a number that is between 1 and the length of the list -1.