Sharing is caring!

python Exercise


Exercise python for beginners on Numbers, Variables and Strings.

  1. The Greeter
    Write a program that asks for the user’s name tells them hello.
  2. What’s My Age Again?
    Ask for their year of birth and compute their age.
    Print out their age in the following format:
    Your age is 25.
  3. Ratio
    Read two numbers in (user input).
    Print out their ratio.
    Figure out how to make this program fail. (There are many ways.)
  4. Sum and Mean
    Read five numbers in.
    Print out their sum and mean.
  5. Swap
    The user enters two numbers.
    Store the numbers in two variables called input1 and input2.
    Swap the values of the two variables so that input1 has the value of input2
    and vice versa.
    Print out the two variables.
  6. Quickswap
    Perform the swap in #5 above in only 1 line of code, and without using any
    variables other than input1 and input2.
Cheap flights with cashback

More exercise

  1. Create a string containing a single quote.
  2. Create a string containing a double quote.
  3. Create a string containing both a single quote a double quote
    10.Create a triple quoted string that contains single and double quotes.
    11.Create a character “a”.
    12.Create a character, then obtain its integer representation.
    13.Given these strings:
  4. >>> s1 = ‘abcd’
  5. >>> s2 = ‘efgh’
    Create a new string composed of the first string followed by (concatenated with)
    the second.
    16.Create a single string containing 5 copies of the string ‘abc’.
    17.Use the multiplication operator to create a “line” of 50 dashes.
    18.Strip all the whitespace characters off the right end of a string.
    19.Center a short string within a longer string, that is, pad a short string with blank
    characters on both right and left to center it.
    20.Convert a string to all upper case.
    21.Split a string into a list of “words”.
    22.Create a string that contains a backslash character using both plain literal string
    and a raw string

Categories: Python


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *