Pt1420
Unit 6
Page 1
5.def mix colors ( primary1 , primary2 ) : i f primary1 == primary2 : return primary1 e l i f primary1 == ”red” and primary2 == ”blue” or primary1 ==
”blue” and primary2 == ”red ”: return ”purple” e l i f primary1 == ”red” and primary2 == ”yellow” or primary1
== ”yellow” and primary2 == ”red ”: return ”orange” e l i f primary1 == ”yellow” and primary2 == ”blue” or primary1
== ”blue” and primary2 == ”yellow ”: return ”green” global primary1 = input (” Please enter a primary color : ”) global primary2 = input (” Please enter another primary color : ”) i f global primary1 != ”red” and global primary1 != ”blue” and global primary1 != ”yellow” or global primary2 != ”red” and global primary2 != ”blue” and global primary2 != ”yellow ”: print (” These are not primary colors . I can ’ t mix them !”) else : secondary color = mix colors ( global primary1 , global primary2 ) print (”When you mix the primary colors , ” , global primary1 , ” and ” , global primary2 , ” , you get the secondary color ,
” , secondary color , ”.” , sep = ’ ’)
6. Public Class BookMain
Public Shared Sub Main
Dim numberOfBook As Integer = 5
Console.WriteLine("{0} Points", GetPointByPurchase(numberOfBook))
End Sub
End Class
Public Module Main
Public Function GetPointByPurchase(ByVal numberOfBook As Integer) As Integer
Select Case numberOfBook
Case 1
GetPointByPurchase = 5
Case 2
GetPointByPurchase = 15
Case 3
GetPointByPurchase = 30
Case >= 4
GetPointByPurchase = 60
Case Else
GetPointByPurchase = 0
End Select
End Function
End Module
7. Console.WriteLine("Enter the number of packages to be purchased.");
if (numberPurchased >= 10 && numberPurchased <= 19) {
discountPercentage = 20; }
else if (numberPurchased >= 20 && numberPurchased <= 49) {
discountPercentage = 30;
}
else if (numberPurchased >= 50 && numberPurchased <= 99) {
discountPercentage = 40;
}