Question

Problem 1 Part A Define a fuction dashes() that draws multiple dashes and takes 3 parameters:...

Problem 1

Part A

Define a fuction dashes() that draws multiple dashes and takes 3 parameters:

1. t, a turtle object

2. length, the length of each dash as well as the space between two consecutive dashes

3. num, the number of dashes to draw

Part B

Write code that produces 10 dashes of length (and gap) 20. HINT: Remember to import turtle in order to create your actual parameters.

Problem 2 Write a function evenIntegers() that takes one parameter:

1. numList, a list of numbers

The function prints the total number of even numbers in a list.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROBLEM-1

Screenshot of output:

Code:

#Part-A

import turtle #Import turtle module for drawing.
t = turtle.Turtle()#Create a turtle object t.
def dashes(t, n, l):#Define the function dashes having parameters turtle object,number of dashes(n),dash length and gap between dashes(l)
for i in range(n):#To create n number of dashes.
t.forward(l)#To create a dash of length l.
t.penup()#To initialize gap between two dashes
t.forward(l)#To specify number of gap between two dashes
t.pendown()#To take the position of the next dash which is going to be drawn in next iteration.
turtle.exitonclick()#To exit from the screen on clicking on the screen.

#Part-B

dashes(t, 10, 20)#To draw 10 dashes of length (and gap) 20.'t' is the turtle object.

PROBLEM-2:

Screenshot of output:

Code:

numList = [1,45,87,22,10,6,12,4]#List of numbers.
def evenintegers(nuLlist):#The function evenintegers() calculates number of even numbers in the list numList which #is passed as parameter.
count = 0#This variables counts the number of even numbers.
for i in range(len(numList)):
if numList[i] % 2 == 0:#If the remainder is 0 then the number is divisible by 2 i.e the number is even.
count += 1#Increment the count as the number is even
print "\nThe list is:"#Print the list
print numList[0:len(numList)]
print "\nNumber of even numbers in the list numlist is:"#Print number of even numbers.
print count
evenintegers(numList)#Call the function to calculate number of even numbers.

Add a comment
Know the answer?
Add Answer to:
Problem 1 Part A Define a fuction dashes() that draws multiple dashes and takes 3 parameters:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...

    C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters. (b) Write a function, sumdixisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6...

  • Answer must be in Python 3 Answer: import turtle def trifecta(size,angle,num): for i in range(num): tri(t,size)...

    Answer must be in Python 3 Answer: import turtle def trifecta(size,angle,num): for i in range(num): tri(t,size) t.right(angle) t = turtle.Turtle() s = turtle.Screen() trifecta(100,25,5) Question 11 Part b (10 points) Write a function named trifecta() that takes three parameters: 1. size 2. angle 3. num trifecta() should call tri() repeatedly so as to draw num triangles, each with sides of length size. Each triangle should be oriented angle degrees clockwise from the preceding triangle. trifecta() should create a turtle and...

  • Python 3.5 Code Part A: 10 points A tick is a short line that is used...

    Python 3.5 Code Part A: 10 points A tick is a short line that is used to mark off units of distance along a line. Write a function named drawTick() that uses a turtle parameter to draw a single tick of specified length perpendicular to the initial orientation of the turtle. The function drawTick() takes two parameters: 1. a turtle, t, that is used to draw 2. an integer, tickLen, that is the length of the tick When drawTick() is...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Define a function called get_n_largest(numbers, n) which takes a list of integers and a value n...

    Define a function called get_n_largest(numbers, n) which takes a list of integers and a value n as parameters and returns a NEW list which contains the n largest values in the parameter list. The values in the returned list should be in increasing order. The returned list must always be of length n. If the number of values in the original list is less than n, the value None should be repeated at the end of the returned list to...

  • help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...

    help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...

  • Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers,...

    Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers, multiplies them together, and prints out the sentence '____ times ____ is ____'. Ask the user for two numbers, and call multiply_and_print with their two numbers as arguments. 2.Write a function called roll_dice that rolls two six-sided dice and prints out the result of each die. Call it three times. (Remember, you can import the random module with the statement import random, and then...

  • Define a function named insert that takes an integer atom and a sorted list as parameters....

    Define a function named insert that takes an integer atom and a sorted list as parameters. The function should return a list with the integer in the correct position in the sorted list. For example: insert [3, (2 4 6 8)] = (2 3 4 6 8) insert 9, ()] = (9) insert[3, (2 3 4 5)] = (23 3 4 5) Note that in the case of that last example, it does not matter which 3 comes first in...

  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • MUST BE IN PYTHON!!!! PLEASE HELP WITH NUMBER 10 & 11A & 11B!!! WIILL VOTE UP!!!...

    MUST BE IN PYTHON!!!! PLEASE HELP WITH NUMBER 10 & 11A & 11B!!! WIILL VOTE UP!!! F=False boolExprs = [T and F, T or F, T and T, F or F trueCount = 0 for expr in boolExprs: if expr: trueCount += 1 print (trueCount) a. 1 b. 2 c. 3 d. 4 e. None of the above Question 10 import tu1rtle s turtle.Screen () t turtle. Turtle () for i in range 4) if i%2 = 1: t.down )...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT