Hw8_Fall_2023
.pdf
keyboard_arrow_up
School
University of California, Berkeley *
*We aren’t endorsed by this school
Course
MISC
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
2
Uploaded by DeaconBat3708
11/9/23, 9:24 AM
Hw8_Fall_2023.ipynb - Colaboratory
https://colab.research.google.com/drive/1_Z5Sl4gxpZUGYbcM_Ac_zvSGKs3iliPa?authuser=1#printMode=true
1/2
Objective: Gain experience with dictionaries by counting the frequency of words in a given text.
Instructions:
Write a function word_frequencies(text: str) -> dict that takes a string as an argument and returns a dictionary with words as keys and
their frequencies as values. Convert the text to lowercase before processing. Ignore punctuations like ., ,, ?, !, and so on. Ignore
common stop words like "and", "the", "is", "in", etc. Test your function with a sample text to verify its correctness.
Sample Input:
text = "Hello, world! The world is beautiful. Hello everyone!"
Sample Output:
{ 'hello': 2, 'world': 2, 'beautiful': 1, 'everyone': 1 }
Exercise: Word Frequencies
#your code here
text = "Hello, world! The world is beautiful. Hello everyone!"
def word_frequencies(text):
text = text.replace('.', '')
text = text.replace('!', '')
text = text.replace('?', '')
text = text.replace(',', '')
text = text.replace('(', '')
text = text.replace(')', '')
text_arr = text.split(' ')
word_dict = {}
for word in text_arr:
word = word.lower()
11/9/23, 9:24 AM
Hw8_Fall_2023.ipynb - Colaboratory
https://colab.research.google.com/drive/1_Z5Sl4gxpZUGYbcM_Ac_zvSGKs3iliPa?authuser=1#printMode=true
2/2
if word not in word_dict:
word_dict[word] = 0
word_dict[word] += 1
return word_dict
print(word_frequencies(text))
{'hello': 2, 'world': 2, 'the': 1, 'is': 1, 'beautiful': 1, 'everyone': 1}
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
CodeWorkout
Gym
Course
Q Search
kola shreya@ columbusstate.edu
Search exercises...
X274: Recursion Programming Exercise: Cannonballs
X274: Recursion Programming Exercise:
Cannonballs
Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top,
sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine.
cannonballs, and so forth.
Given the following recursive function signature, write a recursive function that takes as its argument the
height of a pyramid of cannonballs and returns the number of cannonballs it contains.
Examples:
cannonball(2) -> 5
Your Answwer:
1 public int cannonball(int height) {
3.
4}
Check my answer!
Reset
Next exercise
Feedback
arrow_forward
Gmall
Google Maps
Hürlyet- Habarle..
Office365 Emall
CScl 127, Introduc..
Question-1
1- Get a number from user.
2- If the number is not divisible by 5 then find out how much more you need
so that number becomes divisible by 5. Print the result.
Example-1:
Enter a numnber: 3
We need to add 2 to 3 so that it will be divisible by 5
Example-2:
Enter a number: 9
We need to add I to 9 so that it will be divisible by 5
Question-2
arrow_forward
Q2: Secret Courses
Dan's recently announced that he's teaching n top-secret courses next semester.
Instead of enrolling in them through ACORN, students need to email Dan to
express their interests. These courses are numbered from 1 to n in some arbitrary
order.
In particular, if a student named s is interested in taking a course c, they need to
send an email to Dan containing the message c s. Note that if a student is
interested in taking multiple courses, they need to send multiple emails, one per
course.
Upon receiving a message c s, Dan looks at the list of students already enrolled in
course c. If there's already a student on the list whose name is too similar to s,
Dan assumes s is the same student and ignores the message. Otherwise, he
enrolls s in the course.
Dan considers two names too similar if and only if they have the same length and
differ in at most one letter (note that "a" and "A" are considered the same letter).
For example, "Josh" and "Josh" are too similar. "Sam" and…
arrow_forward
How do I solve this using swift code?
arrow_forward
Credit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with:■ 4 for Visa cards■ 5 for MasterCard credit cards■ 37 for American Express cards■ 6 for Discover cards
In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card is scanned correctly by a scanner. Credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388576018402626):
1. Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number.
2. Now add all single-digit numbers from Step 1.
3. Add all digits in the odd places from right to left in the card number.
4. Sum the results from Steps 2 and 3.
5. If the result from…
arrow_forward
Compare Numbers - Python Language please!
Programming challenge description:
Little Tommy is in kindergarten on the first day of class. His teacher has taught him about inequalities today, and he is learning how to draw crocodiles to represent them. When there are two numbers, A and B, there are three options:1. If A is greater than B, then draw '>'. The crocodile's mouth is pointed toward the bigger number, A.2. If A is less than B, then draw '<'. The crocodile faces B.3. If A is equal to B, draw '='. The crocodile is confused and keeps its mouth shut.Unfortunately, Tommy does not like to do his homework, and has bribed you to write a program to do it for him.
Input:
The input consists of two integers A and B on a line, separated by a space. |A,B| < 2^63.
Output:
Print a line containing the appropriate symbol that describes the relationship between the numbers.
Test 1
Test InputDownload Test 1 Input
35 40
Expected OutputDownload Test 1 Output
<
arrow_forward
Discrete Mathematics:
Assignment details:
Replace all the 0 (Zero) digits in your ID by 4.
Example: If your ID is 38104680, it becomes 38144684
Take the first 6 digits and substitute them in this expression (( A + B) / C) * ((D-E)/F)-2) according to the following table;
Letter
Replace by Digit
Example Digit
A
1st
3
B
2nd
8
C
3rd
1
D
4th
4
E
5th
4
F
6th
6
After substitution your expression will be similar to this (( 3 + 8) / 1) * ((4-4)/6)-2).
Draw a rooted tree that represents your expression.
What is the prefix form of this expression.
3.What is the value of the prefix expression obtained in step 2 above?
arrow_forward
Celebrity problem A celebrity among a group of n people is a person who knows nobody but is known by everybody else. The task is to identify a celebrity by only asking questions to people of the form: ”Do you know him/her?” Solution Select two people from the group given, say, A and B, and ask A whether A knows B. If A knows B, remove A from the remaining people who can be a celebrity; if A doesn’t know B, remove B from this group. Solve the problem recursively for the remaining group of people who can be a celebrity
Which design strategy does the following solution use?
A-)Decrease-by-a-constant factor algorithm
B-)Variable-size-decrease algorithm
C-)Decrease-by-a-constant algorithm
D-)Divide-and-Conquer
arrow_forward
Computer Science
A tool is attached to link 3 of the manipulator. This tool is described by TTW, the tool frame relative to the wrist frame. Also, a user has described his work area, the station frame relative to the base of the robot, as TSB. Write the subroutine Procedure SOLVE(VAR trels: frame; VAR current, near, far: vec3; VAR sol: boolean); where “trels” is the {T} frame specified relative to the {S} frame. Other parameters are exactly as in the INVKIN subroutine. The definitions of {T} and {S} should be globally defined variables or constants. SOLVE should use calls to TMULT, TINVERT, and INVKIN
arrow_forward
Cyclops numbersdef is_cyclops(n):A nonnegative integer is said to be a cyclops number if it consists of an odd number of digits so that the middle (more poetically, the “eye”) digit is a zero, and all other digits of that number are nonzero. This function should determine whether its parameter integer n is a cyclops number, and return either True or False accordingly
n
Expected result
0
True
101
True
98053
True
777888999
False
1056
False
675409820
False
arrow_forward
message-passing (MPI) libraries
Triangular number Series: A triangle number counts the objects that can form an equilateral triangle. The nth triangle number is the number of dots or balls in a triangle with n dots on a side; it is the sum of the n natural numbers from 1 to n. • The formula for the nth triangular number can be expressed as: ?? = ∑ ? ? ?=1 = 1 + 2 + 3 + ⋯ + ? = ?(? + 1) 2 = ( ? + 1 2 ) • The first few triangular numbers are: 0, 1, 3, 6, 10, 15, …… • Pictorially, the triangular numbers can be represented as below: Write a program that generates the triangular number series from the first term up until the n th term. In your program, the user will enter the n number, choose a large number! The sequence should be printed in the correct order. Regarding the number of threads/processes, try at least three different numbers (e.g., 2, 4, 8).
arrow_forward
Q5 PYTHON MULTIPLE CHOICE
Code Example 4-1
def get_username(first, last):
s = first + "." + last
return s.lower()
def main():
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
username = get_username(first_name, last_name)
print("Your username is: " + username)
main()
A. Refer to Code Example 4-1: What is the scope of the variable named s ?
a.
global
b.
local
c.
global in main() but local in get_username()
d.
local in main() but global in get_username()
arrow_forward
Brute force equation solver
this is python program.
Numerous engineering and scientific applications require finding solutions to a set of equations. Ex: 8x + 7y = 38 and 3x - 5y = -1 have a solution x = 3, y = 2. Given integer coefficients of two linear equations with variables x and y, use brute force to find an integer solution for x and y in the range -10 to 10.
Ex: If the input is:
8 7 38 3 -5 -1
Then the output is:
3 2
Use this brute force approach:
For every value of x from -10 to 10 For every value of y from -10 to 10 Check if the current x and y satisfy both equations. If so, output the solution, and finish.
Ex: If no solution is found, output:
No solution
You can assume the two equations have no more than one solution.
Note: Elegant mathematical techniques exist to solve such linear equations. However, for other kinds of equations or situations, brute force can be handy.
''' Read in first equation, ax + by = c '''a = int(input())b = int(input())c = int(input())
''' Read in…
arrow_forward
Nearest polygonal number def nearest_polygonal_number(n, s):
Any positive integer s > 2 defines an infinite sequence of s-gonal numbers whose i:th element is given by the formula ((s-2)i2 - (s-4)i)/2, as explained on the Wikipedia page "Polygonal Number". In this formula, positions start from 1, not 0, and we use the letter i to denote the position since we will be using the letter n for something else. For example, the sequence of "octagonal numbers" that springs forth from s = 8 starts with 1, 8, 21, 40, 65, 96, 133, 176...
Given the number of sides s and an arbitrary integer n, this function should return the s-gonal integer closest to n. If n falls exactly halfway between two s-gonal numbers, return the smaller one.
As you can see from the last row of the previous table, this function must be efficient even for gargantuan values of n. The simplest way to make this function efficient is to harness the power of repeated halving to pull your wagon with a clever application of…
arrow_forward
Decrease-by-Constant-Factor Fake-Coin puzzle method in Java or C++ to find the fake coin out of n coins. Assume the false coin is lighter. Randomly place the false coin among the n coins. Submit results images and code files.
arrow_forward
Python problem
Problem statementDevelop a program that receives a playlist for a game of triqui and determines whether the sequence is valid and, if so, the final result. Player X is always first and O is second.
https://i2.wp.com/www.lacoladerata.co/wp-content/uploads/2016/12/triqui2.png?fit=420%2C201&ssl=11.2 -> 3.3 -> 1.3 -> 1.1 -> 2.1 -> 2.2 -> *
The winner is: O
EntryThe coordinates in format (row, column) of each of the players, alternating between X and O, X plays first. Where 1,1 is the upper left corner and 3,3 is the lower right corner.
The end of the game is given by the character "*".
DepartureIf there is a winner, the message must be "The winner is: X" or "The winner is: O" without the quotes, as the case may be. Player O corresponds to the capital letter o. In the event of a tie, the message “Tie” must be printed, without the quotation marks.
If there is a winner and there are still coordinates, in addition to the message of the winner or tie, it…
arrow_forward
Python: Shopping PlanExample:
assert best_shopping_plan([], 1) == 0 # Alice cannot buy anything as there is no item in the store
assert best_shopping_plan([1], 1) == 1 # Alice can only buy that one item of price 1 given her budget amount
assert best_shopping_plan([1,2], 1) == 1 # Alice can only buy that one item of price 1 given her budget amount
assert best_shopping_plan([1,1,2], 2) == 2 # Alice can buy one item of price 2, or she can buy the two items of price 1
assert best_shopping_plan([1,2,3], 3) == 3 # Alice can buy one item of price 3, or she can buy the two items of price 1 and 2
assert best_shopping_plan([1,2,3,4], 10) == 7 # The best Alice can buy is for items of prices 3 and 4
assert best_shopping_plan([1,2,2,3,3,3], 10) == 6 # The best Alice can buy is for items of prices 3 and 3
assert best_shopping_plan([1,1,1,3,5,5], 7) == 6 # The best Alice can buy is for items of prices 1 and 5
arrow_forward
Entered
Answer Preview
Result
Message
correct
(923,998)
(923,998)
(2398,2171)
(2398, 2171)
correct
(2,808)
(2,808)
Your answer isn't a number
incorrect
(it looks like a list of numbers)
At least one of the answers above is NOT correct.
(1 point) Consider the elliptic curve group based on the equation
y²
= x + ax + b
x3
mod p
where a =
2440, b = 295, and p
=
3391.
We will use these values as the parameters for a session of Elliptic Curve Diffie-Hellman Key Exchange. We
will use P = (2, 808) as a subgroup generator.
You may want to use mathematical software to help with the computations, such as the Sage Cell Server
(SCS).
On the SCS you can construct this group as:
G=Elliptic Curve (GF(3391), [2440,295])
Here is a working example.
(Note that the output on SCS is in the form of homogeneous coordinates. If you do not care about the details
simply ignore the 3rd coordinate of output.)
Alice selects the private key 18 and Bob selects the private key 15.
What is A, the public key of Alice?…
arrow_forward
Chirality
def is_left_handed(pips):
Even though this has no effect on fairness, pips from one to six are not painted on dice just any which way, but so that pips on the opposite faces always add up to seven. (This convention makes it easier to tell when someone tries to use crooked dice with certain undesirable pip values replaced with values that are more desirable for the cheater.) In each of the 23 = 8 corners of the cube, exactly one value from each pair of forbidden opposites 1-6, 2-5 and 3-4 meets two values chosen from the other two pairs of opposites. You can twist and turn any corner of the die to face you, and yet two opposite sides never spread into simultaneous view.
This discipline still allows for two distinct ways to paint the pips. If the numbers in the corner shared by the faces 1, 2, and 3 read out clockwise as 1-2-3, that die is left-handed, whereas if they read out as 1-3-2, that die is right-handed. Analogous to a pair of shoes made separately for the left and…
arrow_forward
1. Come and Get Sum
by CodeChum Admin
You think you're smart huh? I bet you cant add even add
two numbers together! Prove me wrong and I might just
back off.
Input
1. The first integer
Constraints
This is a whole number.
2. The second integer
Constraints
This is a whole number.
Output
The first line will contain a message prompt to input the
first integer.
The second line will contain a message prompt to input
the second integer.
The last line will contain the whole equation with the
sum.
Enter the first - number: 1
Enter the second- number: 2
1.+23
arrow_forward
Skydiving
Bibi is a skydiving instructor. Before carrying out skydiving
activities, Bibi will always ask the name, height, and age
of the participants. Bibi's participants is always 2 people.
To make it easier to remember their identities, Bibi gave
them a paper to write down their identity. But because
they are very enthusiastic in doing skydiving, they write
their identity in a single line only (for both of the
participants), so it wasn't quite neat and it made difficult
for Bibi to see it, and resulted in the skydiving process
being disturbed. As one of the organizer committee, you
do not want this activity to be disturbed and plan to
provide a program that provides their identity neatly to
Bibi.
Format Input
Input consists of 1 line. It contains the identity of 2 people
in a row Ni, Ti, Ui - the name, height, and age of the i-th
participant.
Format Output
The output consists of 6 lines. The first line, "Name 1: N1".
The second line, "Height 1: T1". The third line, "Age: U1".
For…
arrow_forward
Four in a row is a game in which players take turns adding tokens to the columns on the game board.
Tokens fall to the lowest position in the chosen column that does not already have a token in it. Once one of the players has placed four of their tokens in a straight line (either vertically, horizontally, or diagonally), they win the game
If the board is full and no player has won, then the game ends in a draw.
TASK
Using the following class descriptions, create a UML diagram and a version of Four in a row game
The game must allow for a minimum of two and maximum of four players
The game must allow each player to enter their name(duplicate names should not be accepted)
The game should give the players the ability to choose how many rows (between four and ten), and how many columns (between four and ten) the game board should have.
The code uses several classes, including "Player", "Board","Game" and exceptions for handling errors such as invalid moves and full columns.…
arrow_forward
Programming langauge: Python
Prompt: Pick a genre of your choice and provide average movie’s ratings by the following four time intervals during which the movies were released withiin 10 years group (i.e. 1970 to 1979, 1980 to 1989, 1990 to 1999, 2000 to 2009)
Mock dataframe: *attached screenshot*
arrow_forward
language: HTML
design a simple shopping cart with only 3 items (names can be left as placeholders like "Item 1", "Item 2"). There should be a quantity adder as well as a function that enables the user to see the subtotal of all the item prices together (prices can be a random number)
arrow_forward
Friend’s Party Circle:
There are a few friends living in the same area. They have a party every weekend and the place of party change each week. It is always a difficult task to select a place which is nearest for everyone. They all decided to take advantage of Computer Science to solve this problem.
Names of friends are Ahmed, Rehman, Careem, Basit, Dawood, Ghani, and Farid. Ahmed lives at 5 minutes’ walk from rehman and at 10 minutes’ walk from Careem. Careem lives at 3 minutes’ walk from Dawood. Rehman lives at 4 minutes’ walk from Basit and 2 minutes’ walk from Dawood. Dawood lives at two minutes’ walk from Farid. Ghani lives at 2 minutes’ walk from Basit.
If we represent a graph G = V (V, E) in which set of vertices are home of each Friend and an edge represents a path between two homes. Provide the adjacency matrix of directed graph of the graph G.
In above directed graph G. You are required to devise an algorithm to find all possible paths.
arrow_forward
Java Script
Create a function that calculates the number of different squares in an n * n square grid. Check
the Resources tab.
Examples
numberSquares (2)→ 5
numberSquares (4) 30
numberSquares(5) 55
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Related Questions
- CodeWorkout Gym Course Q Search kola shreya@ columbusstate.edu Search exercises... X274: Recursion Programming Exercise: Cannonballs X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine. cannonballs, and so forth. Given the following recursive function signature, write a recursive function that takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains. Examples: cannonball(2) -> 5 Your Answwer: 1 public int cannonball(int height) { 3. 4} Check my answer! Reset Next exercise Feedbackarrow_forwardGmall Google Maps Hürlyet- Habarle.. Office365 Emall CScl 127, Introduc.. Question-1 1- Get a number from user. 2- If the number is not divisible by 5 then find out how much more you need so that number becomes divisible by 5. Print the result. Example-1: Enter a numnber: 3 We need to add 2 to 3 so that it will be divisible by 5 Example-2: Enter a number: 9 We need to add I to 9 so that it will be divisible by 5 Question-2arrow_forwardQ2: Secret Courses Dan's recently announced that he's teaching n top-secret courses next semester. Instead of enrolling in them through ACORN, students need to email Dan to express their interests. These courses are numbered from 1 to n in some arbitrary order. In particular, if a student named s is interested in taking a course c, they need to send an email to Dan containing the message c s. Note that if a student is interested in taking multiple courses, they need to send multiple emails, one per course. Upon receiving a message c s, Dan looks at the list of students already enrolled in course c. If there's already a student on the list whose name is too similar to s, Dan assumes s is the same student and ignores the message. Otherwise, he enrolls s in the course. Dan considers two names too similar if and only if they have the same length and differ in at most one letter (note that "a" and "A" are considered the same letter). For example, "Josh" and "Josh" are too similar. "Sam" and…arrow_forward
- How do I solve this using swift code?arrow_forwardCredit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with:■ 4 for Visa cards■ 5 for MasterCard credit cards■ 37 for American Express cards■ 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card is scanned correctly by a scanner. Credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388576018402626): 1. Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. 2. Now add all single-digit numbers from Step 1. 3. Add all digits in the odd places from right to left in the card number. 4. Sum the results from Steps 2 and 3. 5. If the result from…arrow_forwardCompare Numbers - Python Language please! Programming challenge description: Little Tommy is in kindergarten on the first day of class. His teacher has taught him about inequalities today, and he is learning how to draw crocodiles to represent them. When there are two numbers, A and B, there are three options:1. If A is greater than B, then draw '>'. The crocodile's mouth is pointed toward the bigger number, A.2. If A is less than B, then draw '<'. The crocodile faces B.3. If A is equal to B, draw '='. The crocodile is confused and keeps its mouth shut.Unfortunately, Tommy does not like to do his homework, and has bribed you to write a program to do it for him. Input: The input consists of two integers A and B on a line, separated by a space. |A,B| < 2^63. Output: Print a line containing the appropriate symbol that describes the relationship between the numbers. Test 1 Test InputDownload Test 1 Input 35 40 Expected OutputDownload Test 1 Output <arrow_forward
- Discrete Mathematics: Assignment details: Replace all the 0 (Zero) digits in your ID by 4. Example: If your ID is 38104680, it becomes 38144684 Take the first 6 digits and substitute them in this expression (( A + B) / C) * ((D-E)/F)-2) according to the following table; Letter Replace by Digit Example Digit A 1st 3 B 2nd 8 C 3rd 1 D 4th 4 E 5th 4 F 6th 6 After substitution your expression will be similar to this (( 3 + 8) / 1) * ((4-4)/6)-2). Draw a rooted tree that represents your expression. What is the prefix form of this expression. 3.What is the value of the prefix expression obtained in step 2 above?arrow_forwardCelebrity problem A celebrity among a group of n people is a person who knows nobody but is known by everybody else. The task is to identify a celebrity by only asking questions to people of the form: ”Do you know him/her?” Solution Select two people from the group given, say, A and B, and ask A whether A knows B. If A knows B, remove A from the remaining people who can be a celebrity; if A doesn’t know B, remove B from this group. Solve the problem recursively for the remaining group of people who can be a celebrity Which design strategy does the following solution use? A-)Decrease-by-a-constant factor algorithm B-)Variable-size-decrease algorithm C-)Decrease-by-a-constant algorithm D-)Divide-and-Conquerarrow_forwardComputer Science A tool is attached to link 3 of the manipulator. This tool is described by TTW, the tool frame relative to the wrist frame. Also, a user has described his work area, the station frame relative to the base of the robot, as TSB. Write the subroutine Procedure SOLVE(VAR trels: frame; VAR current, near, far: vec3; VAR sol: boolean); where “trels” is the {T} frame specified relative to the {S} frame. Other parameters are exactly as in the INVKIN subroutine. The definitions of {T} and {S} should be globally defined variables or constants. SOLVE should use calls to TMULT, TINVERT, and INVKINarrow_forward
- Cyclops numbersdef is_cyclops(n):A nonnegative integer is said to be a cyclops number if it consists of an odd number of digits so that the middle (more poetically, the “eye”) digit is a zero, and all other digits of that number are nonzero. This function should determine whether its parameter integer n is a cyclops number, and return either True or False accordingly n Expected result 0 True 101 True 98053 True 777888999 False 1056 False 675409820 Falsearrow_forwardmessage-passing (MPI) libraries Triangular number Series: A triangle number counts the objects that can form an equilateral triangle. The nth triangle number is the number of dots or balls in a triangle with n dots on a side; it is the sum of the n natural numbers from 1 to n. • The formula for the nth triangular number can be expressed as: ?? = ∑ ? ? ?=1 = 1 + 2 + 3 + ⋯ + ? = ?(? + 1) 2 = ( ? + 1 2 ) • The first few triangular numbers are: 0, 1, 3, 6, 10, 15, …… • Pictorially, the triangular numbers can be represented as below: Write a program that generates the triangular number series from the first term up until the n th term. In your program, the user will enter the n number, choose a large number! The sequence should be printed in the correct order. Regarding the number of threads/processes, try at least three different numbers (e.g., 2, 4, 8).arrow_forwardQ5 PYTHON MULTIPLE CHOICE Code Example 4-1 def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) main() A. Refer to Code Example 4-1: What is the scope of the variable named s ? a. global b. local c. global in main() but local in get_username() d. local in main() but global in get_username()arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT