{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Print the number of hours in 4 weeks, using as many variables as useful (at least 5 variables)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a and x are int variables. Suppose that they already contain a value. Does this cell leave the value of x identical to what is was before the execution of the cell? Write a thorough comment making me understand that you have understood." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a=x\n", "a=a+1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a and x are int variables. Suppose that they already contain a value. Does this cell leave the value of x identical to what is was before the execution of the cell? Write a thorough comment making me understand that you have understood." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x=x+1\n", "x=x" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a and x are int variables. Suppose that they already contain a value. Does this cell leave the value of x identical to what is was before the execution of the cell? Write a thorough comment making me understand that you have understood." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a=x\n", "x=a+1\n", "x=a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a and x are int variables. Suppose that they already contain a value. Does this cell leave the value of x identical to what is was before the execution of the cell? Write a thorough comment making me understand that you have understood." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x=a+1\n", "x=x" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a and x are int variables. Suppose that they already contain a value. Does this cell leave the value of x identical to what is was before the execution of the cell? Write a thorough comment making me understand that you have understood." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "z=x\n", "a=z\n", "x=a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Assign the value of 100 to the variable m and \"days\" to s.\n", "With the help of the two variables, write one single line of code where the output after execution would be 100 days.\n", "\n", "Provide two answers using two different print methods." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Extract the letter 'B' from \"Bingo!\"." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Extract the letter \"u\" from \"Constitution\"." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given any string s (which can also be empty), which of the following expressions gives the same value as the original value of s regardless of the initial value of s? Write a comment on each one making me understand that you have understood.\n", "- ('a'+s)[1:]\n", "- s+\"\"\n", "- s[0]+s[1:]\n", "- s[0:]\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given two string variables containing your first name and your last name, write Python code that prints out a single word which is a concatenation of the first two letters of your first name and the last two letters of your last name." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Assume A is a string variable. Write Python code that prints the position of the second occurrence of _zip_ in A, together with the previous character. For example, for A=\"the zip-files are unzipped\" it should print 20 and \"n\", while for A=\"zip files are compressed\" it should print -1 (do not worry about what it prints next in this case).\n", "
I think it is obvious that the program must work for any string A, simply changing the string at it beginning, without having to manually change numbers inside. If you are able to write a program with numbers manually written inside, try to find a way to get those numbers automatically. \n", "
Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
" For this exercise do NOT use the round function, it would be too easy!\n",
" I think also it is obvious that the program must work for any number with a dot, regardless the amount of digits before and after the dot. \n",
" Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
"
I remind you that, even though we have always printed the result of the find method, you can also put it inside a variable or use it as argument for other find methods.\n",
"