python代写 python作业代写 python程序代写 代写python程序

Python入门程序代写

  • write a method dayType that take a day number as parameter and return weekday if it the day number correspond to weekday and weekend otherwise. 

        assume the day number will be from 1 to 7 and 1 is Saturday.

2. Write a function, print_card(card), to print the value of a playing card where card is a dictionary with 2 keys: suit and value. The suit is one of

['Hearts','Diamonds','Spades','Clubs']

and the value is a number from 1 to 13 inclusive. Remember that the card values 1 and 11,12,13 have special names:

1 is 'Ace'

11 is 'Jack'

12 is "Queen'

13 is "King'

Your function should print the card as Value of Suit, e.g.

print_card({suit:'hearts',value:1})  prints "Ace of Hearts"

print_card({suit:'hearts',value:2})  prints "Two of Hearts"

print_card({suit:'hearts',value:13})  prints "King of Hearts"


Hint: create a list called

  value_names=["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]

  

and use the card value to index into this list


3. Write a function, same_suit(a,b), which returns true if the two cards (a and b) have the same suit.  

The suit is one of

['Hearts','Diamonds','Spades','Clubs']

and the value is a number from 1 to 13 inclusive.


4. Write a function, same_value(card1,card2), which returns true if the two cards have the same value.  

The suit is one of

['Hearts','Diamonds','Spades','Clubs']

and the value is a number from 1 to 13 inclusive, and the cards are dictionaries, e.g.


same_value( {'suit':'Clubs', 'value':13},{'suit':'Hearts', 'value':13}) returns True

same_value( {'suit':'Clubs', 'value':13},{'suit':'Clubs', 'value':12}) returns False

same_value( {'suit':'Clubs', 'value':13},{'suit':'Hearts', 'value':12}) returns False


5. Write a function, remove_card(card,hand), which returns the new hand with the specified card removed.

e.g. if hand = [

{'suit':'Clubs', 'value':13},{'suit':'Hearts', 'value':13},

{'suit':'Clubs', 'value':9},{'suit':'Spades', 'value':1}

]

and card is {'suit':'Hearts', 'value':13}

then remove_card(card,hand) would return 


 [

{'suit':'Clubs', 'value':13},{'suit':'Clubs', 'value':9},{'suit':'Spades', 'value':1}

]


6. Write a function, find_matches(card,hand), which returns all of the cards in the specified hand which match the card, i.e. have the same value or the same suit


e.g. if hand = [

{'suit':'Clubs', 'value':13},{'suit':'Hearts', 'value':13},

{'suit':'Clubs', 'value':9},{'suit':'Spades', 'value':1}

]

and card is {'suit':'Spades', 'value':9}

then remove_card(card,hand) would return 


 [

{'suit':'Clubs', 'value':9},{'suit':'Spades', 'value':1}

]


7. Write a function, first_article(sentence), which takes a string, sentence, and returns the first article (i.e. "a", "an", "the") that appears in the list and returns "none" if there are no articles. Hint: use sentence.split() to turn it into a list of words.


first_article('See the dog has a friend') --> 'the'

first_article(['Where are you now') --> 'none'


8. Write a function, age(y), which takes an integer y representing a person's age and returns 'error' if y is negative, 'youth' if they are under 18, 'senior' if they are 65 or older, and 'adult' otherwise.


9. Write a function, grade(students), which accepts a list of students as shown below where each student has an id, an exam score, and a list of homework scores.  It returns the same list, but adds their grade which is the sum of their exam score and their homework scores. 

So if students is the following:

[ {'id':1442,  'exam':90,  'hws':[90,100]},

  {'id':1102,  'exam':80,  'hws':[100,90]},

  {'id':1998,  'exam':80,  'hws':[80,80]},

  {'id':1995,  'exam':100,  'hws':[100,100]}

]

The call grade(students) will return this list

[ {'id':1442,  'exam':90,  'hws':[90,100], 'grade':280},

  {'id':1102,  'exam':80,  'hws':[100,90], 'grade':270},

  {'id':1998,  'exam':80,  'hws':[80,80],  'grade':240},

  {'id':1995,  'exam':100,  'hws':[100,100], 'grade':300}

]


10. Write a function, eurodate(date), which converts US style dates (06/30/17) into European style dates (30.06.17). You may assume that the month, day, and year all have 2 digits.

京ICP备2025144562号-1
微信
程序代写,编程代写
使用微信扫一扫关注
在线客服
欢迎在线资讯
联系时间: 全天