Home > Computer Programming > Functions practice

Functions practice

September 9, 2013 Leave a comment Go to comments
  • Write a function that takes a list of integers and returns the largest one.
  • Write a function that takes a list A and a number N and returns the number of times N appears in A.
  • Write a function that takes a block of text and returns the largest word.
  • Write a function that takes a block of text and returns the number of vowels in it.
  • Write a function that takes a block of text and a letter and returns the number of occurrences of the letter in the text.
  • Write a function that simulates coin-flipping by taking a number N and returning the percentage of times the coin came up heads when flipped N times.
  • Write a function that prints your name like this:
          A     
         A A    
        AAAAA   
       A     A  
      A       A 

        BBBB
        B   B
        BBBB
        B   B
        BBBB

         CCCC
        C
       C
        C
         CCCC
  • Write a function that takes any string and prints it out like this (much harder!)
  •           A     BBBB    CCCC
             A A    B   B  C   
            AAAAA   BBBB  C
           A     A  B   B  C   
          A       A BBBB    CCCC
  • Write a function that takes a number and returns a list of its factors
  • Write a function that takes two numbers and returns (a) their highest common factor, (b) their lowest common multiple
  • Write a function that takes a number and returns true if that number is prime and false if not
  • Write a function that takes a string and returns true if it is a palindrome and false if not
  • Write a function that takes a string and returns the string converted to Morse code
  • Use the Morse code function to output sound to the PC speaker
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s