WSQ04 – Sum of Numb3rs

--Originally published at Wonder Universe

Soooo, I have a problem! I need to sum the integer numbers of a very specific range and I need to do it now! What the heck I am going to do?!?!?! It’s not like I’m a program-master-party-dude…or am I?

WSQ04_1

So, I came up with this. Bassically I make a function asking for two numbers, the lower and the higher. I make a range list where I sum every number ’till I get to the higher and then (and only then) I return the sum.

WSQ04_2

See?!? It even works!!!


# WSQ09 – Multipart Data and Files

--Originally published at マルコ

Your Assignment

So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). You will want to look at how to use and return a tuple from a function and how to open and read text files line by line.

files

files2

Featured image:

http://www.pixiv.net/member_illust.php?mode=medium&illust_id=25862501

 


# WSQ08 – Yo Soy 196

--Originally published at マルコ

What to Do

Your job is to create a program that asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”

Details

The report must show:
  • The range of numbers analysed (lower to upper bound)
  • The number of natural palindromes (no addition to inverse needed)
  • The number of non-Lycherels encountered (become palindromes)
  • The number of Lycherel number candidates (that did not converge to palindrome)

Since you will not be able to prove that a number is Lycherel (since you cannot computer forever to check), our definition for a Lycherel candidate will be if a number does not converge after 30 iterations of applying the addition to the inverse.

lyrchel

lyrchel2

Featured image:

# 196 Dex


# WSQ07 – Lists

--Originally published at マルコ

What to Do

Create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

Details

For the Python group, you want to be using Lists. For the C++ group you can do this with arrays or Vectors, but you will need to know eventually how to do both.

Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

lists

lists2

Featured image:

http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14071780


# WSQ06 – Factorial Calculator

--Originally published at マルコ

What to Do

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

Details

For the Python group, resist the urge to call math.factorial(n). Yes that would solve the problem but what would we do if there was no math.factorial() and we had no internet to find someone’s solution?

There are two basic approaches: a loop with an accumulator of the multiplication and a recursive solution. Choose one and implement that. Once that is done, try the other way.

If you used a while loop for the solution with a loop, try structuring this with a for loop (or vice-versa).

factorial

factorial2

Featured image:

 

 


# WSQ 05 – On To Functions

--Originally published at マルコ

What to Do

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.You will go back and do WSQ01 – Fun with Numbers again.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

Funnum

Funnum2

Featured image: 

http://www.pixiv.net/member_illust.php?mode=medium&illust_id=34076723

 

 


# WSQ04 – Sum of Numbers

--Originally published at マルコ

What to Do

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

Notice our sum starts with zero (why?) and then we add each number in the range provided by the user. Just for fun, what is the mathematical formula to do this calculation?

Example Run

We will calculate the sum of integers in the range you provide.
Please give us the lower bound:  1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55

squeares

squeares2

Featured image:

 


# WSQ 03 – Pick a Number

--Originally published at マルコ

What to Do

There are different ways to make that happen, you choose which one works best for you.Write a program that picks a random integer in the range of 1 to 100.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

Adivina

Adivina2

Featured Image:

 


# WSQ 02- Temperature

--Originally published at マルコ

What to Do

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given. Your output might look like the following

Example Run

What is the temperature in Fahrenheit? 100

A temperature of 100 degrees Fahrenheit is 37 in Celsius

Water does not boil at this temperature (under typical conditions).

Temperature

Temperature2

Featured image:

http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9545915

 


# WSQ01 – Fun with Numbers

--Originally published at マルコ

What to Do

Ask the user for two integer values, then use those two values to calculate and show the following:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

Code:

Capture

Fun with numbers2