Sofyware Development Flashcards
(17 cards)
How do you round a number
Number =round(1.67830)
Print(number)
How do you round to a whole number
Number = 4.6783
Print(int(number))
How to do an if statement
Ticket = str(input(“do you wish to but a ticket”))
If ticket == “Y”:
Print(“welcome to the ticket office”)
How to do an else statement
Ticket = str(input(“do you wish to but a ticket”))
If ticket == “Y”:
Print(“welcome to the ticket office”)
Else:
Print(“we are sorry to hear that”)
Print(“please return soon”)
How do you use complex conditions such as, and, or
Ticket = str(input(“do you wish to but a ticket”))
If ticket == “Y”:
Print(“welcome to the ticket office”)
Else:
Print(“we are sorry to hear that”)
Print(“please return soon”)
Age = int(input(“please enter your age”))
If age >= 5 and age <= 17:
Print(“please purchase a junior ticket”)
If age > 17 and age < 65:
Print(“please purchase an adult ticket”)
If age >= 65:
Print(“get a senior ticket”)
How do to a fixed loop
For counter in range(4):
Print(“this is a fixed loop”)
Fixed loop with user input
Times = int(input(“enter a number”))
For counter in range(times):
Print(“i must try harder”)
More about the range statement
Total = 0
Print(“please enter the 3 test marks”)
For counter in range(1,4):
Print(“please enter test”,counter)
Mark = int(input())
Total = total + mark
Print(“the total number of marks =“,total)
How to do a conditional loop
Choice = “”
While choice != “Y” and choice != “N”:
Choice = str(input(make your choice -Y/N”))
Print(“thank you for making your choice”)
Input validation with conditional loop
Score = int(input(“please enter your score”))
While not(score >= 10 and score <=20)):
Print(“your score must be between 10 and 20”)
Score = int(input(“please enter your score”))
How to store multiple values using lists
Names = [ “anton”, “Dominic”, “Joseph”, “Michael”, “sean”, “kiera”, “Niamh”]
Ages = [15, 12, 18, 25, 21, 23, 20]
For counter in range(len(names)):
Print( names[counter], ages[counter] )
Pre defined function
Numbers = [12,4,67,55,29,289,23,99,6]
Largest = max(numbers)
Print(“the largest value is”,largest)
Print(“the smallest value is”,min(numbers))
Running a total
Total = 0
Items = [12,3,54,35,23,56,34,3,77,9]
For count in range(len(items)):
Total = total + items[count]
Print(“the total=“,total)
Input validation
Number = int(input(“enter a value between 0 and 10”))
While number <0 or number >10:
Print(“your value was not between 0 and 10”)
Number = int(input(“enter a value again”))
Print(“number=“, number)
Traversing an array
Values = [12,3,54,35,23,56,34,3,77,9]
Print(“the following values are > 50”)
For count in range(len(values)):
If values[count]>50:
Print(values[count])
How to import a random number between 0 and 1
Import random
Print (random.random())
How to do a running total within a loop
People = int(input(“how many people are there”)
Total = 0
For x in range (people):
Age = int(input( “what is your age”))
Total = total + age
Print(“the total age is”, total)