Question

In: Computer Science

Use Turtle graphics to draw your first name or your nickname if over 6 letters.           Just...

Use Turtle graphics to draw your first name or your nickname if over 6 letters.          

Just initials of your first & last name is OK if you add another feature such as color.

My initials are J.S but I don't know how to color them.

Here is my code:

 Python program to print nick name if a name is greater than 6 character
  or initials if the color if given
"""

import turtle as T


fName, lName = input('Enter name: ').split()
color = input('Enter Color: ')

T.fillcolor(color)

if color is '':
  if len(fName)+len(lName) > 6:
    T.write(fName, font=("Arial",32,"normal"))
  else:
    T.write(fName + " " + lName,font=("Arial",32,"normal"))
else:
  T.write(fName[0] + " " + lName[0], font=("Arial",32,"normal"))

Solutions

Expert Solution

Answer :

I have edited your code and now it is working fine. We should understand the difference between fill color() and color() function of turtle class.

fill color() - It is used to color the entire body of the given shape.

color() - It is used basically to color the text.

So here we have to use color() instead of fill color(), also I had move this line to the else part as if the user doesn't enter the initial so in that case, we don't have to color the text.

Python code: Given below is fully commented code.

import turtle as T #import library
fName, lName = input('Enter name: ').split() #taking first name and last name input from user
color = input('Enter Color: ') #taking color input from user
if color is '': #if no color is selected then
if len(fName)+len(lName) > 6: #if lenght of full name exceed 6 then print only first name
T.write(fName, font=("Arial",32,"normal"))
else: #print full name if lenght is less than 6
T.write(fName + " " + lName,font=("Arial",32,"normal"))
else: #if color is entered then
T.color(color) #apply color to text
T.write(fName[0] + " " + lName[0], font=("Arial",32,"normal")) #print the inital of first and last name

Given below is the screenshot of code and its output for better understanding of indentation of python code and inputs:

Code:

Output:

HOPE YOU GOT IT !!


Related Solutions

I need to draw my first name using Turtle. I am struggling with "P" and "A"...
I need to draw my first name using Turtle. I am struggling with "P" and "A" this is what I have import turtle turtle.setup(800, 700) window = turtle.Screen() window.reset() window.bgcolor('cornsilk') t = turtle.Turtle() t.color('blue') t.pencolor('red') t.turtlesize(6) t.speed(2) t.up() t.setposition(-50, 0) t.pendown()#Drawing letter T t.forward(40) t.back(20) t.right(90) t.forward(50) t.left(90) t.penup() t.forward(70) t.left(90) t.forward(25) t.pendown() t.circle(25)# Drawing letter O t.penup() t.left(180) t.forward(25) t.left(90) t.forward(10) t.pendown()#Drawing letter N t.left(90) t.forward(50) t.right(150) t.forward(60) t.left(150) t.forward(53) t.back(53) t.right(90) turtle.done()
Spell your name using capital letters. If there are letters in your name that do not...
Spell your name using capital letters. If there are letters in your name that do not code for an AAs, replace them by P, H, and W. Shorten or lengthen the name to make it a heptapeptide. What is its charge at pH 1, 7, and 13? What is its pI? name: Travana so, Thr-Arg-Ala-Val-Ala-Asn-Ala
Assignment Write a program using turtle graphics which writes your initials, or any other three unique...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique letters, to the display. Look to your program for lab 1 for reminders of how to use turtle graphics. Functions that must be written: def drawLetter (x, y, letterColor): Write three functions, one for three unique letters. Personally, I would write drawA, drawR, and drawS. Each function must draw that letter to the screen. The x and y values determine the upper left-hand location...
Each of the first 6 letters of the alphabet is printed on a separate card. The...
Each of the first 6 letters of the alphabet is printed on a separate card. The letter “a” is printed twice. What is the probability of drawing 4 cards and getting the letters f, a, d, a in that order? Same question if the order does not matter.
Write a function that draw your initials. (Using python 3 turtle) (T, S)
Write a function that draw your initials. (Using python 3 turtle) (T, S)
Name your file “DMx1_Your last name_Your first name.” You can use MS Word to complete the...
Name your file “DMx1_Your last name_Your first name.” You can use MS Word to complete the matrices (go to Insert, Table, Insert table, fill the table). Save the file as a PDF file. If you draw the matrices on paper, take pictures. Make sure the pictures are clear and readable. Insert the pictures in MS Word document and save it as a PDF file. 1. Align using dot matrix: horizontal sequence – AGGCTCCC, vertical sequence – GCGCTCCG. Trace and explain...
A person has to create a code. The code must contain exactly 6 letters. The first...
A person has to create a code. The code must contain exactly 6 letters. The first letter must be a vowel that is not an E or I. The second letter must be either a J, K, or L. The third letter must be a consonant that is not a G or R. The fourth letter must be a vowel that is not an I. The fifth letter must be a consonant. If repetition of letters are not allowed, how...
22. Draw the structure of two steroid hormones and name their use in humans.   23. Draw...
22. Draw the structure of two steroid hormones and name their use in humans.   23. Draw 3 amino acid structures explain their primary uses and sources of the amino acids. 24. Explain the four components of the protein tertiary structure. __________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ ______________________________________________________________________________
Write an assembly language program that prints your first name in the output. Use immediate addressing...
Write an assembly language program that prints your first name in the output. Use immediate addressing with a hexadecimal constant to designate the operand of CHARO for each letter of your name. Comment each line except STOP and END. Cut and paste the Assembler Listing into your document and paste a screen shot of the Output area of the Pep8. Use the name "Kevin" as example Assembler Listing Screen Shot of Output area of the Pep8 program
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name.
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name. using name John Smith phone number 1234567893 Using net beans take the first two letters from smith and first 3 numbers from the phone number and combine them to one line like this sm123.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT