Write an expression whose value is the result of converting the str value associated with s to an int value. So if s were associated with “41” then the resulting int would be 41.

Published by Denis on

1.Using Python 3.4 Write an expression whose value is the result of converting the str value associated with s to an int value. So if s were associated with “41” then the resulting int would be 41.

Answer: str(42)

Elevate Your Writing with Our Free Writing Tools!

Did you know that we provide a free essay and speech generator, plagiarism checker, summarizer, paraphraser, and other writing tools for free?

Access Free Writing Tools

2.Given three int variables that have been given values, areaCode, exchange, and lastFour, write a string expression whose value is the string equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression’s value would be “800-555-1212”. Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression’s value would be “212-867-5309”.

Answer: str(areaCode) + ‘-‘ + str(exchange) + ‘-‘ + str(lastFour)

3.Write an expression whose value is the result of converting the int value associated with x to a str. So if 582 was the int associated with x you would be converting it to the str “582”.

Answer: str(x)

4.Write a statement to set the value of the variable popStr to a string representation of the value assigned to the variable pop.

Answer: popStr = str(pop)

5. Write an expression whose value is the arithmetic sum of the value contained in x, and the all-digit string assigned to s. (Hint: you will need to convert the string to an integer.

Answer: int(s) + x

6. Given four variables that have been given integer values, octet1, octet2, octet3, and octet4, write a string expression whose value is the string equivalent of each these variables joined by a single period (.) So if octet1, octet2, octet3, and octet4 had the values 129, 42, 26, and 212 the expression’s value would be “129.42.26.212”. Alternatively, if octet1, octet2, octet3, and octet4 had the values 192, 168, 1and 44 the expression’s value would be “192.168.1.44”.

Answer: str(octet1) + “.” + str(octet2) + “.” + str(octet3) + “.” + str(octet4)

7. Assume the variable date has been set to a string value of the form mm/dd/yyyy, for example 10/08/2010. (Actual numbers would appear in the string.) Write a statement to assign to a variable named dayStr the characters in date that contain the day. Then set a variable day to the integer value corresponding to the two digits in dayStr.

Answer: dayStr = date[3:5]
day = int(dayStr)

More answered questions UOF MUH4016 

 

Gudwriter Custom Papers

Special offer! Get 20% discount on your first order. Promo code: SAVE20