Photo AI

Button [1.1 - Random number] Write code to do the following: - Generate a random number in the range 100–120 (inclusive) - NSC Information Technology - Question 1 - 2019 - Paper 1

Question icon

Question 1

Button-[1.1---Random-number]--Write-code-to-do-the-following:----Generate-a-random-number-in-the-range-100–120-(inclusive)-NSC Information Technology-Question 1-2019-Paper 1.png

Button [1.1 - Random number] Write code to do the following: - Generate a random number in the range 100–120 (inclusive). - Display the random number in the edRand... show full transcript

Worked Solution & Example Answer:Button [1.1 - Random number] Write code to do the following: - Generate a random number in the range 100–120 (inclusive) - NSC Information Technology - Question 1 - 2019 - Paper 1

Step 1

Button [1.1 - Random number]

96%

114 rated

Answer

To generate a random number in the range of 100 to 120, we will use a random number generator function. After generating the number, we will display it in the edRandomNumber edit box:

random_number = random.randint(100, 120)
edRandomNumber.setText(str(random_number))

Step 2

Button [1.2 - Calculate minutes]

99%

104 rated

Answer

To calculate the minutes required based on the number of participants, we need to perform the following steps:

  1. Extract the number of participants from edtParticipants:
    participants = int(edtParticipants.getText())
    
  2. Set the minutes_per_participant based on the number of participants:
    if participants <= 20:
        minutes_per_participant = 2.5
    elif 20 < participants <= 50:
        minutes_per_participant = 2.3
    else:
        minutes_per_participant = 2.0
    
  3. Calculate the total minutes:
    total_minutes = participants * minutes_per_participant
    
  4. Round the result to two decimal places:
    total_minutes_rounded = round(total_minutes, 2)
    
  5. Display the rounded minutes in edtMinsRounded:
    edtMinsRounded.setText(str(total_minutes_rounded))
    

Step 3

Button [1.3 - Calculate factorial]

96%

101 rated

Answer

To calculate the factorial of a selected number, we can follow these steps:

  1. Extract the selected number from spnNumber:
    selected_number = spnNumber.getValue()
    
  2. Initialize factorial to 1 and use a loop to calculate the factorial:
    factorial = 1
    for i in range(1, selected_number + 1):
        factorial *= i
    
  3. Display the factorial in edtFactorial:
    edtFactorial.setText(str(factorial))
    

Step 4

Button [1.4 - Reverse words]

98%

120 rated

Answer

To reverse the words in a sentence extracted from edtSentence, we will:

  1. Extract the sentence and split it into words:
    sentence = edtSentence.getText()
    words = sentence.split()
    
  2. Reverse the order of words:
    reversed_words = ' '.join(reversed(words))
    
  3. Display the reversed sentence in edtReversedWords:
    edtReversedWords.setText(reversed_words)
    

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;