0% found this document useful (0 votes)
127 views2 pages

Python (2 Different Questions) - 1. Given This Stri.

s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views2 pages

Python (2 Different Questions) - 1. Given This Stri.

s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

  

NEW!
Textbook Solutions Expert Q&A Practice Search  

home / study / engineering / computer science / computer science questions and answers / python (2 different questions): 1. given this string: chain…

Post a question
Welcome to Chegg Study, your start to better grades Show me around Answers from our experts for your tough
homework questions

Question: Python (2 different questions): 1. Given this string: chain = "ABC… Enter question

Python (2 different questions):


Continue to post
1. Given this string:
20 questions remaining
chain = "ABC1DEF2G"
write a loop to extract and output the consecutive "triplets" from the string such that the output
sequence looks like this:
ABC My Textbook Solutions
BC1
C1D
1DE
DEF
EF2 Add a Add a
F2G textbook textbook
Hints: Introduction
1. the boundary of the for loop has to do with the length of the string minus something to Logic...
1st Edition
2. there are only two statements in the loop body; one for getting a slice of 3 characters from the string
View all solutions
for the triplet; one for printing the triplet
Your Answer:
2. Given the following class definition:
from random import randrange Computer Science Chegg
class Die:
tutors who can help right
""" now
One object of this class represnts one die with 6 sides. You can roll the die
to come up with a pseudo random value between 1 and 6.
Matthew Z.
""" 932
University of Colora…
def __init__(self):
"""
Initializes the die to 1. Garikina J.
703
Andhra University B…
"""
self.value = 1
Himani S.
def __str__(self): 62
Msc Computer Scie…
"""
Returns a string representation of the die.
""" Find me a tutor
return "This die has value : " + str(self.value)

def roll(self):
"""
Rolls the die to come up with a pseudorandom value between 1 and 6.
"""
self.value = randrange(1,7)

Write a main program that creates two objects of class Die and rolls them both 10 times. After each roll,
print the value of both dice so you can visually inspect the output to see how many pairs you rolled. Your
program must use a loop to roll 10 times instead of repeating code.
Your Answer:

Expert Answer

sdad504 answered this


Was this answer helpful? 0 0
821 answers

chain = "ABC1DEF2G"
lengthchain=len(chain);
for i in range(0,lengthchain-2):
print(chain[i:i+3]);

import random
class Die:
"""
One object of this class represnts one die with 6 sides. You can roll the die
to come up with a pseudo random value between 1 and 6.
"""
def __init__(self):
"""
Initializes the die to 1.
"""
self.value = 1
def __str__(self):
"""
Returns a string representation of the die.
"""
return "This die has value : " + str(self.value)
def roll(self):
"""
Rolls the die to come up with a pseudorandom value between 1 and 6.
"""
self.value = random.randrange(1,7)
def main():
dice1=Die();
dice2=Die();
for i in range(0,10):
dice1.roll();
dice2.roll();
print(dice1,dice2);

if __name__ == '__main__':
main()

Comment

Questions viewed by other students

Q:
Python Language Problem Please complete the function get_trial_result() and use the test code provided. These are the
definitions of the trial decisions, given a jury of 9 jurors: Guilty - Unanimous; all 9 juror decisions are guilty Guilty - Split; at
least 7 juror decisions(Super Majority) are guilty Hung Jury - Mistrial; less than 7 juror decision are guilty Not Guilty - No
juror...

A:
See answer

Q:
[Java] A palindrome is a word, phrase, or sequence that reads the same backward as forward. Example: madam, civic, kayak,
racecar, mom, dad, noon, rotor, radar, etc. Your task is to read a String input by the user and determine whether the String is
a palindrome or not. Your submission needs to be a word document and it must include a screenshot of the result of
entering a...

A:
See answer
100% (1 rating)

Show more 

ABOUT CHEGG LEGAL & POLICIES CHEGG PRODUCTS AND SERVICES CHEGG NETWORK CUSTOMER SERVICE
Become a Tutor Advertising Choices Cheap Textbooks Online Tutoring Easybib Customer Service
Chegg For Good Cookie Notice Chegg Coupon Solutions Manual Internships.com Give Us Feedback
College Marketing General Policies Chegg Play Study 101 Studyblue Help with Chegg Tutors
Corporate Development Intellectual Property Rights Chegg Study Help Test Prep Help with eTextbooks
Investor Relations International Privacy Policy College Textbooks Textbook Rental Help to use EasyBib Plus
Jobs Terms of Use eTextbooks Used Textbooks Manage Chegg Study
Join Our Affiliate Program Chegg Tutors Terms of Service Chegg Math Solver Digital Access Codes Subscription

Media Center US Privacy Policy Mobile Apps Return Your Books

Site Map Your CA Privacy Rights Textbook Return Policy

Honor Code

© 2003-2019 Chegg Inc. All rights reserved.

You might also like