Strathit.files.wordpress.com



Hello, World!Submit a program that just prints out this:Hello, World!This is just a test run to make sure that our testing system is working correctly for you.Answer:Hello to you, tooWrite a program that asks the user's name, then prints:Hello, <name>!So for example, if my name was?Tara, my interaction with your program should look like:Enter your name: TaraHello, Tara!If my name was instead?James, my interaction with your program should look like:Enter your name: JamesHello, James!Ahoy, me Hearties!Write a program to ask the user for the name of the pirate captain.Your program should then print out?Cap'n <name> says "Ahoy, me Hearties!", with?<name>?substituted with the name of the captain that the user enters. For example:Who is the captain? BlackbeardCap'n Blackbeard says "Ahoy, me Hearties!"Quotes in stringsYou can get a single quote inside a string by using double quoted string:>>> print "They can't do that!"They can't do that!Similarly, you can get a double quote inside a string by using a single quoted string:>>> print '"meow", said the cat.'"meow", said the cat.Python! ^_^After starting to learn about Python, you want to express you newfound joy to your friends via instant messaging. Your favourite happy emoticon is the?Japanese-style emoticon?^_^.When you just finish solving a question, you're super happy and require a larger amount of happiness to be expressed, achieved by adding more underscores between the carets:?^_____^.After telling a couple of your friends how happy you are, writing out these emoticons is becoming tiring due to the underscores you need to type. You decide to use your newfound Python knowledge to help you out!Write a Python program to read in a number, which indicates how happy your emoticon should be. For example:Enter a number: 1^_^Here is another example:Enter a number: 3^___^Difference in AdditionWhilst studying the Python notes, you have a realisation that the?+?operator can mean different things in different contexts.When between two numbers,?+?means numerical addition, but when between two strings,?+?means string concatenation:>>> print 6 + 713>>> print 'NCSS ' + 'Challenge'NCSS ChallengeWrite a program to read two numbers from the user. Your program should first print out what the sum of the two numbers is when they’re treated as strings (concatenation). Your program should then print out what the sum of the two numbers is when they’re treated as integers. For example:Enter a: 6Enter b: 3a + b as strings: 63a + b as integers: 9Here is another example of how your program should work:Enter a: 42Enter b: -17a + b as strings: 42-17a + b as integers: 25 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download