In this collection of challenges you are going to manipulate numbers and perform basic arithmetic operations with numbers as well as use string manipulation techniques to format numbers.

#### Challenge #1: Square Number

1 2 3 |
number = int(input("Type a number:")) squareNumber = number * number print("The Square Number is " + str(squareNumber)) |

**int()**function on line 1.

Converting a user input to an integer is required to do some maths based calculations such as the calculation used on line 2.

Vice versa, we can convert an integer to a string using the **str()** function on line 3.

#### Challenge #2: Total 100

1 2 3 |
number = int(input("Type a number:")) total100 = 100 - number print("The Total 100 Number is " + str(total100)) |

**int()**function on line 1 to convert a user input to an integer and the

**str()**function on line 3 to convert an integer to a string.

#### Challenge #3: Odd or Even?

1 2 3 4 5 |
number = int(input("Type a number:")) if (number % 2) == 0: print("This number is even.") else: print("This number is odd.") |

#### Challenge #4: Telephone Number

1 2 3 |
number = input("Type your telephone number usin 11 digits:") telephoneNumber = "(" + number[0:5] + ") " + number[5:8] + " " + number[8:11] print(telephoneNumber) |

**slice a string**to extract certain characters. This is done by using the following approach: using the square brackets on a string: e.g. string[startingPosition:endPosition] will retrieve all the characters of the string between the startingPostion and the endPosition.

Notice that in this challenge we are treating the user input as a string not a number. (We did not convert the user input on line 1 to an integer as we did in previous challenges using the int() function.) Each digit of our number/string is in fact a character from the string.

#### Challenge #5: Palindrome

1 2 3 4 5 6 7 8 |
number = input("Type a large number:") palindrome = "" for digit in number: palindrome = digit + palindrome palindrome = number + palindrome print("The palindrome number is " + palindrome) |

**iterate**(loop through) through each character of a string one at a time using a

**for loop**.

Notice that in this challenge, once again we are treating the user input as a string not a number. (We did not convert the user input on line 1 to an integer as we did in previous challenge using the **int()** function.) Each digit of our number/string is in fact a character from the string.

#### Challenge #6: Number Upgrade

1 2 3 4 5 6 7 8 9 10 11 |
number = input("Type a large number:") numberUpgrade = "" for digit in number: if int(digit)==9: newDigit = 0 else: newDigit = int(digit) + 1 numberUpgrade = numberUpgrade + str(newDigit) print("The Number Upgrade is " + numberUpgrade) |

**iterate**(loop through) each character of a string one at a time using a

**for loop**.

We retrieve each digit (character) one at a time and have to convert these digits to integers using the **int()** on line 5 and 8 to be able to perform maths calculation with them (adding them up).

#### Challenge #7: Spaced Out Number

1 2 3 4 5 6 7 |
number = input("Type a large number:") spacedOutNumber="" for digit in number: spacedOutNumber = spacedOutNumber + "-" + str(digit) print("The Spaced Out Number is " + spacedOutNumber[1:]) |

**iterating**(looping through) each character of a string one at a time using a

**for loop**.

Notice the slicing approach used to truncate the string from its first digit on line 7 using the string[1:] which returns all the characters from a string from position 1. (So slicing out the first character which is at position 0).

#### Challenge #8: Total Number

1 2 3 4 5 6 7 |
number = input("Type a large number:") totalNumber = 0 for digit in number: totalNumber += int(digit) print("The Total Number is " + str(totalNumber)) |

**iterating**(looping through) each character of a string one at a time using a

**for loop**.

#### Challenge #9: Plus Minus

1 2 3 4 5 6 7 8 9 |
number = input("Type a large number:") plusMinusNumber = 0 plusminus = 1 for digit in number: plusMinusNumber += int(digit) * plusminus plusminus = plusminus * (-1) print("The Plus Minus is " + str(plusMinusNumber)) |

**iterating**(looping through) each character of a string one at a time using a

**for loop**.

#### Challenge #10: Digit Grouping

Ask the user to enter any large number (e.g. at least 3 digits long). The program should display the result of formatting this number using the comma. For instance if the user enters 65738924 the program should return 65,738,924.

1 2 3 4 5 6 7 8 9 10 11 12 13 |
number = input("Type a large number:") digitGroupingNumber = "" counter=0 for digit in number[::-1]: if counter==3: digitGroupingNumber = digit + "," + digitGroupingNumber counter=0 else: digitGroupingNumber = digit + digitGroupingNumber counter+=1 print("The Digit Grouping Number is " + digitGroupingNumber) |

**negative step**in our for loop using the [::-1] notation on line 5.