Search CSNewbs
304 results found with an empty search
- Python | Section 2 Practice Tasks | CSNewbs
Test your understanding of inputs in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python - Section 2 Practice Tasks Task One: Food & Colour Ask a user to input their favourite colour and their favourite food and then print a response using both answers. Requirements for a complete program: Use only one print line. Include both of the user's answers in the print line. Include capital letters, full stops and no irregular spacing in the printed line. Remember: Break up variables in a print line by using commas or plus signs between each part of the "sentence" . Example solutions: What is your favourite colour? green What is your favourite food? cheese Yum! I'll have green cheese for dinner tonight! What is your favourite colour? purple What is your favourite food? ice cream Let's have purple ice cream for breakfast! Task Two: Trivia Question Create a program that asks the user to input an answer to a trivia question of your choice then prints the correct answer with their response too. Requirements for a complete program: Only two lines. Include capital letters, full stops and no irregular spacing in the printed line. Example solution: What is the capital city of Botswana? Windhoek Correct answer: Gaborone. Your answer: Windhoek What is the closest planet to Earth? Mars Correct answer: Mars. Your answer: Mars Task Three: Getting to School Create a program that asks the user how they get to school and how many minutes it takes them (using int ). Then print an appropriate response that uses both variables . Requirements for a complete program: Use only one print line. Include both of the user's answers in the print line. Include capital letters, full stops and no irregular spacing in the printed line. Example solution: How do you get to school? car How many minutes does it take you? 45 Really? It takes you 45 minutes to get here by car? How do you get to school? walking How many minutes does it take you? 20 Really? It takes you 20 minutes to get here by walking? ⬅ 2b - Inputting Numbers 3a - Data Types ➡
- 6.1 - Legal Considerations | F161 | Cambridge Advanced National in Computing | AAQ
Learn about legislation and regulations related to application development, including the Data Protection Act, Computer Misuse Act and Freedom of Information Act. Resources based on Unit F161 (Developing Application Software) for the OCR Cambridge Advanced Nationals in Computing (H029 / H129) AAQ (Alternative Academic Qualification). Qualification: Cambridge Advanced Nationals in Computing (AAQ) Certificate: Computing: Application Development (H029 / H129) Unit: F161: Developing Application Software 6.1 - Legal Considerations Watch on YouTube : Computer Misuse Act Data Protection Act UK General Data Protection Regulation Freedom of Information Act Privacy and Electronic Communications Regulations Independent bodies UK Information Commissioner's Office You need to know the latest version and main purpose of each act /regulation , as well as actions taken to comply with the act and the impacts of not complying with it. You must also understand how Privacy and Electronic Communications Regulations (PECR ) relate to the Data Protection Act and UK General Data Protection Regulation (UK GDPR ), and the role of the Information Commissioner's Office (ICO ) in the UK. What You Need to Know Computer Misuse Act ? YouTube video uploading soon Data Protection Act ? YouTube video uploading soon UK GDPR ? YouTube video uploading soon Freedom of Information Act ? YouTube video uploading soon PECR ? YouTube video uploading soon ICO & Independent Bodies ? YouTube video uploading soon Q uesto's Q uestions 6.1 - Legal Considerations: 1. What? [2 ] 2. What? [1 ] 3. What? [1 ] 4. What? [1 ] ? D id Y ou K now? 5.3 - Policies Topic List
- HTML Guide 3 - Text Tags | CSNewbs
Learn how to use tags to format text in HTML, including how to underline, italicise and embolden text. Also, learn about heading size and paragraphs. 3. Tags for Text HTML Guide Watch on YouTube: Remember to write the tags for everything you want the user to see between the and tags. Headings Time to add text to your web page such as headings and paragraphs. To write a large heading , use and To write headings in a smaller size, use numbers between 1 and 6. Add a large heading and a sub-heading to your webpage. paragraph Paragraphs Typing text between the and tags will create a paragraph . Add at least three different paragraphs to your webpage. bold underline italics Bold, Underline & Italics You can format your text by changing it to be bold , underlined or italicised (slanted). Now you have text on your web page, you can add hyperlinks to take viewers to different websites. In the paragraphs you have already written, add at least 1 bold tag, 1 underline tag and 1 italics tag. 2. Essential Tags HTML Guide 4. Hyperlinks
- Python | 5b - Sleep | CSNewbs
Learn how to delay processes using the sleep command in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python 5b - Sleep Using Sleep To pause a program, import sleep from the time library . Type the word sleep followed by the number of seconds that you wish the program to break for in brackets . It must be a whole number . Below is an example of a program that imports the sleep command and waits for 2 seconds between printing: from time import sleep print ( "Hello!" ) sleep(2) print ( "Goodbye!" ) You can implement the sleep command within a for loop to produce an effective timer that outputs each second waited to the screen: You could also use a variable instead of a fixed value with the sleep command such as below: from time import sleep for second in range (1,11): print (second) sleep(1) from time import sleep seconds = int ( input ( "How many seconds should I sleep? " )) print ( "Going to sleep..." ) sleep(seconds) print ( "Waking up!" ) Sleep Task ( Slow Calculator) Create a slow calculator program that needs time to think in between calculations. Print a message to greet the user , then wait 3 seconds and ask them to enter a number . Wait another 3 seconds and ask them to enter a second number . Wait 2 more seconds , print “Thinking…” then 2 seconds later print the total of the two numbers added together . Example solution: ⬅ 5a - Rando m 5c - Date & Time ➡
- 1.2 - Storage Media | Unit 2 | OCR Cambridge Technicals | CSNewbs
Learn about secondary storage types such as solid-state, magnetic, optical and paper. Based on the 2016 OCR Cambridge Technicals Level 3 IT specification for Unit 2 (Global Information). 1.2 - Storage Media Exam Board: OCR Specification: 2016 - Unit 2 Data can be stored on a variety of storage media , each with its own benefits and drawbacks . Magnetic Storage Optical Storage A magnetic hard disk drive (HDD ) is the most common form of secondary storage within desktop computers. A read/write head moves nanometres above the disk platter and uses the magnetic field of the platter to read or edit data. Hard disk drives can also be external and connected through a USB port . An obsolete (no longer used) type of magnetic storage is a floppy disk but these have been replaced by solid state devices such as USB sticks which are much faster and have a much higher capacity. Another type of magnetic storage that is still used is magnetic tape . Magnetic tape has a high storage capacity but data has to be accessed in order (serial access ) so it is generally only used by companies to back up or archive large amounts of data . Optical storage uses a laser to project beams of light onto a spinning disc, allowing it to read data from a CD , DVD or Blu-Ray . This makes optical storage the slowest of the four types of secondary storage. Disc drives are traditionally internal but external disc drives can be bought for devices like laptops. Magnetic Storage Characteristics: ✓ - Large CAPACITY and cheaper per gigabyte than solid state . X - Not DURABLE and not very PORTABLE when powered on because moving it can damage the device. ✓ - Relatively quick ACCESS SPEED but slower than Solid State . Optical Storage Characteristics: X - Low CAPACITY : 700 MB (CD ), 4.7 GB (DVD ), 25 GB (Blu-ray ). X - Not DURABLE because discs are very fragile and can break or scratch easily. ✓ - Discs are thin and very PORTABLE . X - Optical discs have the Slowest ACCESS SPEED . Magnetic Disks are spelled with a k and Optical Discs have a c. Solid State Storage Paper Storage There are no moving parts in solid state storage. SSD s (Solid State Drives ) are replacing magnetic HDDs (Hard DIsk Drives) in modern computers and video game consoles because they are generally quieter , faster and use less power . SSDs can also be external . A USB flash drive ( USB stick ) is another type of solid state storage that is used to transport files easily because of its small size. Memory cards , like the SD card in a digital camera or a Micro SD card in a smartphone , are another example of solid state storage. Paper storage includes printed or hand-written documents, notes, forms, schedules and maps. Paper is relatively inexpensive in small quantities but it can take up a lot of space compared to small devices like USB sticks. Producing paper is environmentally damaging and requires physical security methods to keep safe. Paper, such as a timetable, can be written on if times change and easily carried on a person. However, paper in the form of an essay must be re-printed to add changes . Solid State Characteristics: ✓ - High CAPACITY but more expensive per gigabyte than magnetic . ✓ - Usually DURABLE but cheap USB sticks can snap or break . ✓ - The small size of USB sticks and memory cards mean they are very PORTABLE and can fit easily in a bag or pocket. ✓ - Solid State storage has the fastest ACCESS SPEED because they contain no moving parts . Paper Storage Characteristics: X - Low CAPACITY as each page can only hold a certain amount of information. Paper also takes up physical space . X - Poor DURABILITY as paper can easily tear and become damaged in rain. ✓ / X - PORTABILITY varies as single sheets of paper can be easily folded and placed in a pocket. However, large stacks of paper can be difficult and expensive to transport. X - Paper's ACCESS SPEED , in terms of searching for a specific item, is slow , especially if the paper storage has not been organised efficiently . Q uesto's Q uestions 1.2 - Storage Media: 1. State 3 examples of each type of storage media . For example, a CD for optical storage. [3 each ] 2. Compare each type of storage media in terms of capacity , durability , portability and access speed . You may decide to do this as a table or poster. [16 ] 3. Identify the most suitable device (not the media ) and justify its suitability for the following scenarios: a. Backing up a large database at the end of each day. [5 ] b. Keeping a copy of a cleaning schedule for hotel staff. [5 ] c. Making copies of a promotional video to hand out to audience members at a dancing event. [5 ] 1.1 - Holders of Information Topic List 1.3 - Access & Storage Devices
- 2.1 - Information Styles | Unit 2 | OCR Cambridge Technicals | CSNewbs
Learn about the wide range of style data and information can be presented in, both digitally and physically. Based on the 2016 OCR Cambridge Technicals Level 3 IT specification for Unit 2 (Global Information). 2.1 - Information Styles Exam Board: OCR Specification: 2016 - Unit 2 There are many different ways that information can be styled and presented , both on-screen and physically . There are many more benefits and limitations to using each information style but some key ideas have been described below. T Text Text is a written (or typed ) format of information. ✓ Text provides detailed summaries and explanations . ✓ The format of text can be changed to suit its purpose (e.g. include bullet points or different colours). ✓ Text can be written in different languages so that all literate people can understand. X Large amounts of text can be difficult and time-consuming to read. It is generally less engaging than most other methods. X Text may include spelling errors or be factually incorrect . Graphics Graphics are a visual form of information. Examples include logos , photographs and diagrams . ✓ Graphics are multilingual - they can be understood by anybody regardless of their spoken language. Companies like IKEA will use the same graphics globall y . ✓ Graphics can present an idea or message immediately and can use associations (e.g. the colour red is associated with temperature or anger). ✓ Graphics are a more engaging method of presenting information than text. X Images may take longer to load over a data-restricted network, for example, images in an email may not be automatically downloaded. Video Videos are visual formats of information, often with audio . ✓ More engaging and easier to follow than reading large amounts of text. ✓ Videos can be used to convey a message in a short space of time , e.g. television adverts. ✓ Audio can be added to videos such as music for engagement or narration to explain a process. X Videos usually take up a relatively large amount of storage space , longer videos may take time to upload / download / transfer along a network. X Videos take a long time to create including filming, editing and narration. Animated Graphics Animated graphics are images with multiple frames , such as an animation of the heart showing individual steps that a user can pause and step through in their own time. ✓ Can be used to show a process and is easier to understand than reading text. ✓ Can be understood by all ages and language speakers . X Creating an animated graphic takes time to create , especially educational resources with multiple frames and annotation. 9 Numerical Numerical information is represented by numbers . This can include a wide array of different information including statistics, financial data, dates, ages and distances . ✓ Statistical data is easier to understand and manage in a numerical format than standard text - 234,567 is simpler to work with than "two hundred and thirty-four thousand, five hundred and sixty-seven". ✓ Numerical data can be exported into spreadsheets and presented as graphs to visualise the dat a . X Long numbers can be entered by humans incorrectly and lead to incorrect results . X Formatted data like telephone numbers cannot be stored as numerical because numerical does not allow spaces and does not allow the number to start with 0 . Audio Audio is an information type using sound waves. A common form of audio is music , such as the millions of tracks stored in music libraries like Spotify and YouTube. Non-music examples include spoken instructions and podcasts . ✓ Users can listen to information when they are otherwise busy and could not read, such as when walking or driving. ✓ Visually impaired users who are unable to read can still hear audio and interact with voice recognition software . ✓ Some users prefer listening to instructions rather than reading text . X Audio may not be suitable in some environments e.g. noisy areas . X Words may be misheard and misunderstandings made, possibly due to pronunciations or accents. Tactile Images Tactile images are a form of physical information that can be interpreted by touch . Specialist software is used to create raised lines on paper that people can experience by touching . Geographers can create 3D physical objects of environments such as valleys or volcanoes. This allows researchers and land surveyors to have a better understanding of a geographic area. ✓ Users can better understand a physical environment or prospective design if it is physically built. ✓ Visually-impaired users can feel the object instead of being able to see it. ✓ The tactile image can be used as a prototype for a target audience to feel and comment on. X It is difficult to share a tactile image without physically moving it, unlike digital or paper information styles. X Creating a tactile image requires specialist equipment like a 3D printer. *screams* Subtitles Subtitles are a textual form of information that can be shown along with visual data such as a video. Subtitles are written to transcribe audio , such as speech, into words . ✓ Hearing-impaired users can access audio information formats such as video by reading the subtitles. ✓ Subtitles can be used in noisy environments or when sound cannot be played. ✓ Subtitles can be used for translated speech , such as in promotional videos or television programmes. X Auto-generated subtitles are often incorrect . X Subtitles written by a human take a long time to type up and sync in time with the audio. Tables & Spreadsheets Tables and spreadsheets can store both numerical and textual data ready for analysis . Examples include simple database tables and financial spreadsheets of a company's profits this year. Microsoft Access is an example of database software that uses tables and Microsoft Excel is an example of spreadsheet software. When using spreadsheets (or databases) records can be locked ('record locking' ) so that only one person can make edits at any one time . Edits will be saved before unlocking the file. This will stop data being incorrectly overwritten and will ensure that the data in the spreadsheet is up-to-date , accurate and fit for purpose . Spreadsheets can be linked to other documents such as forms to directly import data from. This data can be ordered into different groups and conditional formatting can be used to automatically organise and style the data. Graphs and charts can be created using values stored in a spreadsheet to easily visualise the data . Modelling can be used to see the effect of variable changes (e.g. will raising the price of one product affect overall profit?). Database tables use queries (advanced searches) to find and display data based on given criteria (such as all males under 35). Mail merge can be used to automatically send emails to the customers highlighted in the query . A report can be generated from the query results to display the information in a structured format . This can be used to make decisions and analyse data . Boolean Boolean is a data type that can only have one of two specified values . These values are most commonly 'True' and 'False' or sometimes 'yes' and 'no'. Braille Braille is an example of a tactile image that can be physically touched . Braille characters represent letters or numbers that can be 'read' by touch - used primarily by those with visual impairments . Devices like braille terminals convert characters on a screen into braille, line-by-line so that blind people can understand the information through touch . A braille printer is used to output braille dots onto paper. ✓ Allows visually impaired users to interact with a computer system using a braille terminal . ✓ A braille printer can print documents written using braille to be given to blind people to 'read'. X Braille terminals can only display a limited amount of information at a time. X Braille is not used by many people except visually impaired people so few resources are written using braille. Charts & Graphs Charts and graphs can be used to present numerical data in a format that is easier to visualise and understand . They can be labelled to show different data values and they make it easier for viewers to identify trends and make comparisons between data. Large quantities of data, like census results, are easier to visualise in a graph than reading huge tables of numbers. ✓ Charts present numerical data in a format that is easier to visualise and understand . ✓ Charts and graphs can summarise information into one image data that would take paragraphs to explain in text. ✓ Displaying information in a graph allows users to easily identify trends and make comparisons between data . X Charts can be misleading or can display incorrect information if the numerical data is wrong. Q uesto's Q uestions 2.1 - Information Styles: 1. Describe the following information styles : a. Tactile Images [2 ] b. Braille [2 ] c. Boolean [2 ] 2. Describe two advantages and two disadvantages for each of the following information styles : a. Text [8 ] b. Graphics [8 ] c. Video [8 ] d. Animated Graphics [8 ] e. Numerical [8 ] f. Audio [8 ] g. Tactile Images [8 ] h. Subtitles [8 ] i. Braille [8 ] j. Charts & Graphs [8 ] 3a. Spreadsheets and database tables can be record locked . Explain what record locking is and why it is used . [4 ] 3b. Describe different ways that spreadsheets can be used. [6 ] 3c. Describe different ways that databases can be used. [6 ] 1.7 & 1.8 - Internet Pros & Cons 2.2 - Information Classification Topic List
- Greenfoot Tutorial | CSNewbs
A tutorial to understand how to create a game in Greenfoot. A simple step-by-step guide and walkthrough featuring all code needed for the Eduqas GCSE 2016 specification. A Tutorial to Creating a Greenfoot Game Greenfoot Home Greenfoot is software that uses the programming language Java to make simple games. This is called object-orientated programming (OOP ) because objects are coded to interact in a visual environment. Work your way through the following tutorial to create a game similar to one required in the WJEC/Eduqas 2016 specification Component 2 exam . Topic Links: Starting from Scratch & Populating the World Move with Arrow Keys Move Randomly & Bounce on Edge Remove Objects Play Sounds The Counter Extension Ideas According to the 2016 specification, in the Eduqas exam, you will use Greenfoot version 2.4.2 , despite the fact that Greenfoot is now on version 3.6.1 . This means that some newer code won't work! This guide here will work on version 2.4.2 . Just make sure you are also using version 2.4.2 - see the download page for help. Watch on YouTube:
- 11 Graphical User Interface | CSNewbs
Learn how to create and use a simple graphical user interface (GUI) in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. Python 11 - GUI Graphical User Interface In Python, you don’t have just to use a text display; you can create a GUI (Graphical User Interface ) to make programs that look professional. This page demonstrates the basic features of Python’s built-in GUI named tkinter . You can add images, labels, buttons and data entry boxes to develop interactive programs . Hyperlinked sections covered on this page: Setup: Title, Size & Background Creating Elements: Labels, Entry Boxes, Buttons, Images, Message Boxes Displaying Elements: Pack, Place, Grid Inputs & Outputs GUI Tasks Setup Setup: Title, Size & Background Firstly, import the tkinter command and set tkinter.Tk() to a variable such as window . GUI code can be quite complicated with multiple elements so it is sensible to use a comment for each section. Setting the title , size and background colour of your window is optional but can be easily set up at the start of your code. The .geometry() command sets the size of the window. The first number is the width , and the second number is the height . The .configure() command can be used to set the background colour . For a full list of compatible colours, check here . import tkinter #Setting up the Window window = tkinter.Tk() window.title( "Graphical User Interface" ) window.geometry( "400x400" ) window.configure(background = "lightblue" ) import tkinter #Setting up the Window window = tkinter.Tk() window.title( "Example Number Two" ) window.geometry( "300x400" ) window.configure(background = "darkorchid3" ) Creating Elements Creating Elements: Labels, Entry Boxes, Buttons, Radio Buttons, Images, Message Boxes Labels label1 = tkinter.Label(window, text = "Hello there" ) label1 = tkinter.Label(window, text = "Hello there" , fg = "black" , bg = "lightblue" , font = ( "Arial" , 12)) Simple label with default formatting: Label with custom formatting: No elements will appear in your window until you write code to put them there. See the 'Displaying Elements' section further down. Entry (Text) Boxes Simple entry box with default formatting: entry1 = tkinter.Entry(window ) Entry boxes will appear blank , the 'Example Text' shown in the images has been typed in. Entry box with custom formatting: entry1 = tkinter.Entry(window, fg = "blue" , bg = "gray90" , width = 12, font = ( "Arial" ,12)) Buttons The command property of a button is a subroutine that will be called when the button is pressed . The subroutine must be written above the button creation code. def ButtonPress (): #Code here runs when the button is pressed button1 = tkinter.Button(window, text = "Click Me" , fg = "black" , bg = "gold2" , command = ButtonPress) Radio Buttons The Radiobutton element is a multiple-choice option button . A variable needs to be created to track which option has been selected, in this example it is ‘choice ’. Each radio button needs to be linked to the variable and given a unique value (e.g. 0, 1, 2). The radio button with the the value of 0 will be automatically selected when the window opens . Although not shown below, the .set() command can also be used to select a specific radio button , e.g. choice.set(2) . choice = tkinter.IntVar() radio1 = tkinter.Radiobutton(window, text = "Breakfast" , variable = choice, value = 0) radio2 = tkinter.Radiobutton(window, text = "Lunch" , variable = choice, value = 1) radio3 = tkinter.Radiobutton(window, text = "Dinner" , variable = choice, value = 2) Message Boxes You need to import messagebox from tkinter before you can use message boxes . You only need to do this once in your program and it sensible to have it at the very start after you import tkinter (and any other libraries). from tkinter import messagebox tkinter.messagebox.showinfo( "Information" , "Welcome to the program!" ) tkinter.messagebox.showerror( "Error" , "There is a problem with the program." ) if (tkinter.messagebox.askyesno( "Warning" , "Have you understood the instructions?" )) == True : tkinter.messagebox.showinfo( "Warning" , "Thank you for understanding." ) else : tkinter.messagebox.showinfo( "Warning" , "Please read the instructions again." ) Yes / No Message Box Clicking Yes (True ) Clicking No (False ) Images Tkinter supports the image file types .png and .gif . The image file must be saved in the same folder that the .py file is. Resize the image in separate image editing software such as Paint to a specific size . Tkinter does not support all image file types, such as .jpg. Use an application like Microsoft Paint to save an image with a different extension like .png. photo1 = tkinter.PhotoImage(file = "hamster.png" ) photoLabel1 = tkinter.Label(window, image = photo1) An image can be turned into a clickable button rather than a label. def ButtonPress (): #Code here runs when the button is pressed photo1 = tkinter.PhotoImage(file = "hamster.png" ) button1 = tkinter.Button(window, image = photo1, command = ButtonPress) photo1 = tkinter.PhotoImage(file = "hamster.png" ) window.iconphoto( True , photo1) The icon of the window can be changed to an image . Displaying Elements: Pack, Place and Grid Pack .pack() puts the element in the centre of the window, with the next packed element immediately below. window.mainloop() should always be your last line of code in every program, after you have packed, placed or gridded your elements. Displaying Elements labelAdd.pack() buttonAdd.pack() labelMinus.pack() buttonMinus.pack() window.mainloop() Place The .place() command allows an element to be placed in specific coordinates , using x (horizontal ) and y (vertical ) axes. labelAdd.place(x = 25, y = 15) buttonAdd.place(x = 12, y = 35) labelMinus.place(x = 90, y = 15) buttonMinus.place(x = 83, y = 35) window.mainloop() Grid The .grid() command is used to create a grid system to set the row and column . Remember Python starts counting at 0 . You can use padx and pady to add extra space (x is horizontal , y is vertical ). labelAdd.grid(row = 0, column = 0, padx = 10, pady = 5) buttonAdd.grid(row = 1, column = 0, padx = 10) labelMinus.grid(row = 0, column = 1, padx = 10, pady = 5) buttonMinus.grid(row = 1, column = 1, padx = 10) window.mainloop() Inputs & Outputs Inputs and Outputs .config to Change an Element .config() overwrites the property of an element. It can be used with elements such as labels and buttons to change how they appear. label1.config(text = "Warning!" ) The example below (not showing setup and packing) adds 1 to a total variable when the button is pressed . Config is used in two ways: to display the updated total and to change the background of the label to green. def AddOne (): global total total = total + 1 labelTotal.config(text = total, bg = "green" ) total = 0 buttonAdd = tkinter.Button(window, text = "Add" , command = AddOne) Below is a similar program in full that increases or decreases and displays a total when the buttons are pressed . #Setup import tkinter window = tkinter.Tk() total = 0 #Button Presses def AddOne (): global total total = total + 1 labelTotal.config(text = total) def MinusOne (): global total total = total - 1 labelTotal.config(text = total) #Create Elements labelTotal = tkinter.Label(window, text = total, font = ( "Arial" ,14)) buttonAdd = tkinter.Button(window, text = "+" , width = 6, bg = "green" , command = AddOne) buttonMinus = tkinter.Button(window, text = "-" , width = 6, bg = "red" , command = MinusOne) #Display Elements buttonAdd.pack() buttonMinus.pack() labelTotal.pack() window.mainloop() .get to Input a Value .get() returns the value of an element such as an entry box , label or the choice variable if using radio buttons . The value of the element should be stored in a variable so it can be used elsewhere, for example: name = entryName.get() number = int (entryNumber.get()) Use int when getting a value that is an integer : The full program example below checks that the values typed into the username and password entry boxes are correct . Error Messages #Setup import tkinter from tkinter import messagebox window = tkinter.Tk() window.title( "Login" ) #Button Presses def CheckDetails (): username = entryUsername.get() password = entryPassword.get() if username == "Bob Bobson" and password == "cabbage123" : tkinter.messagebox.showinfo( "Success" , "Welcome " + username) else : tkinter.messagebox.showerror( "Invalid ", "Those details are incorrect." ) #Create Elements labelUsername = tkinter.Label(window, text = "Username:" ) labelPassword = tkinter.Label(window, text = "Password" ) entryUsername = tkinter.Entry(window) entryPassword = tkinter.Entry(window) buttonLogin = tkinter.Button(window, text = "Login" , command = CheckDetails) #Display Elements labelUsername.grid(row = 0, column = 0) entryUsername.grid(row = 0, column = 1) labelPassword.grid(row = 1, column = 0) entryPassword.grid(row = 1, column = 1) buttonLogin.grid(row = 2, column = 0) window.mainloop() .bind for Key Presses (& Close Window) .get() will run a specific function when a certain key is pressed. The name of the key must be surrounded by < > brackets and speechmarks . Any associated subroutine of a key bind will need a parameter : event has been chosen and set to None . The code below closes the window using the .destroy() command when the Esc key is pressed. def Close (event = None ): window.destroy() window.bind( "" , Close) The code below will activate the button (and display a message box) by clicking on it but also by pressing the Enter ( Return ) key . def ButtonPress (event = None ): tkinter.messagebox.showinfo( "Success" , "The button was activated" ) button1 = tkinter.Button(window, text = "Press Me" , command = ButtonPress) window.bind( "" , ButtonPress) GUI Tasks GUI Programs to Make Making a program using a GUI can be overwhelming and you must decompose the problem - take it step by step : Import tkinter and create the window (set the title, size and background colour). Create the elements you will need such as labels , buttons and entry boxes . Put the components in the window using pack , place or grid . Write the subroutines for any button presses . These are written at the top of the program after the window setup. Consider your variables - do any need to be set at the start ? Have you made them global if they’re needed within a subroutine ? Put window.mainloop() as the final line of code, only have it once. Use #comments in your code to break up the different sections, the key four sections are shown below. #Setup #Button Presses #Create Elements #Display Elements GUI Task 1 (Random Number Generator ) Generate a random number between 1 and 100 when the button is pressed and display it in a label. Extension idea: Use entry boxes to allow the user to manually input the minimum and maximum value. Example solution: GUI Task 2 (Currency Exchange ) Enter a decimal value and convert it from British pounds to American dollars. You can search for the current exchange rate. Extension idea: Show the conversion rate for other currencies such as Euros and Japanese Yen. Example solution: GUI Task 3 (Random Quote Generator ) Create a list of quotes and use the choice command from the random library to select one to be displayed in a label when the button is clicked. Extension idea: Have a separate text box and button to add more quotes to the list. Example solution: GUI Task 4 (Colour Changer ) When the button is clicked change the background colour of the button with .config to the RGB colour code in the entry box. This should be # followed by 6 hexadecimal values (0-9, A-F). Extension idea: Have an error pop up in a message box if the colour code is incorrect - it must be exactly 7 characters long and start with a hashtag. Example solutions: GUI Task 5 (Class Captain Votes ) Use radio buttons to vote for different candidates in a class vote. Use an if statement when the button is pressed to check which radio button is selected using .get() and the variable you've assigned to the radio buttons ('choice' if you've followed the code in the radio buttons section on this page). Use .config to overwrite a label's value. Remember any variables you want to use in subroutines must be globalised. Extension idea: Stop the count after a certain number - e.g. 30 votes recorded. Example solution: ⬅ Section 10 Practice Tasks 12 - Error Handling ➡
- 4.1 - Security Considerations | F161 | Cambridge Advanced National in Computing | AAQ
Learn about security threats, including botnets and DDoS attacks and both physical and digital security mitigations. Resources based on Unit F161 (Developing Application Software) for the OCR Cambridge Advanced Nationals in Computing (H029 / H129) AAQ (Alternative Academic Qualification). Qualification: Cambridge Advanced Nationals in Computing (AAQ) Certificate: Computing: Application Development (H029 / H129) Unit: F161: Developing Application Software 4.1 - Security Considerations Watch on YouTube : Security threats Physical security Digital security You need to know the risks that specific security threats pose to applications , including botnets , DDoS attacks , hacking and malware . You need to know how both physical security mitigations (e.g. biometrics , locks and RFID ) and digital security mitigations (e.g. encryption , firewalls and anti-malware ) protect application software against threats . What You Need to Know Security Threats ? YouTube video uploading soon Physical Security Mitigations ? YouTube video uploading soon Digital Security Mitigations ? YouTube video uploading soon Q uesto's Q uestions 4.1 - Security Considerations: 1. What? [2 ] 2. What? [1 ] 3. What? [1 ] 4. What? [1 ] ? D id Y ou K now? 3.2 - Protocols Topic List 5.1 - Testing
- Python | 5c - Date & Time | CSNewbs
Learn how to use time commands to display the current date and time in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python 5c - Time & Date ctime() The easiest way to output the current time and date is to use the ctime() command. Import the ctime command from the time library before you use and print it: from time import ctime print ( "Current time:" , ctime()) = Current time: Wed Sep 13 16:07:20 2023 This will print the time and date, but it looks rather unprofessional, and the exact format depends on the type of system that you are currently running so it may vary for different users. Date / Time Task 1 ( Dentist Surgery) Print a greeting for a dentist surgery with the current date and time. Example solution: Welcome to Greenvale Dentist Surgery, it is currently: Wed Sep 13 16:16:24 2023 strftime() A better alternative to the ctime() command is to use strftime() which stands for str ing f rom time as you can select specific parts of the date and time to display. This command requires a directive to be written with a percentage symbol as a string in the brackets . For example, the current hour (%H ), minute (%M ) and second (%S ) can be printed between colons to show the time . from time import strftime print ( "The current time is" , strftime( "%H:%M:%S" )) = The current time is 13:18:57 There are many different directives that you can use to display exactly what you are looking for, such as: from time import strftime day = strftime( "%A" ) print ( "The current day is" , day) month = strftime( "%B" ) print ( "The current month is" , month) year = strftime( "%Y" ) print ( "The current year is" , year) = The current day is Thursday The current month is September The current year is 2023 The following directives can be used with strftime(). Don't forget that directives must be typed within speech marks . Date - Weekday: %a – Current day of the week abbreviated (e.g. Sun, Mon) %A – Current day of the week in full (e.g. Sunday, Monday) %w – Current day of the week in chronological order (0 is Sunday and 6 is Saturday) %W – Current week number (e.g. 01, 26, 52) Month: %d – Current day of the month (e.g. 01, 11, 31) %m – Current month as a number (e.g. 01, 06, 12) %b – Current month abbreviated (e.g. Jan, Jun, Dec) %B – Current month in full (e.g. January, December) Year: %y – Current year abbreviated (e.g. 16, 17) %Y – Current year in full (e.g. 2016, 2017) %j – Current day of the year (e.g. 001, 150, 365) Time - Hour: %H – Current hour in 24-hour clock (e.g. 00, 12, 20) %I – Current hour in 12-hour clock (e.g. 01, 08, 12) %p – Whether it is currently AM or PM Minute: %M – Current minute (e.g. 00, 30, 59) Second: %S – Current second (e.g. 00, 30, 59) More Directives - %z – Current time difference from UTC (Co-ordinated Universal Time) (e.g. +0000, -0500, +1100) %Z – Current time zone (e.g. GMT Standard Time, EST, CST) Just looking for a quick date or time display and not bothered about customisation? Try these: %c – Current date and time in full (e.g. Tue Feb 19 13:35:20 2016) %x – Current date (e.g. 19/02/16) %X – Current time (13:36:20) Date / Time Task 2 ( Calendar App ) Create a program that asks the user if they want to see the current date , the current time or 'other '. Use the strfftime directives above to show what the user asks for. It's up to you which directives you use for the 'other' option , such as displaying the current day of the year (%j ) or current week of the year (%W ). Example solutions: Type TIME for the current time, DATE for the current date or OTHER: TIME The current time is 13:46PM Type TIME for the current time, DATE for the current date or OTHER: DATE The date today is Thursday 14 September 2023 Type TIME for the current time, DATE for the current date or OTHER: OTHER Did you know today is day number 257 of 2023? Between Dates You may want to work out the number of days between two dates . This can be done by importing the date command from the timedate library. Below is a simple example: from datetime import date date1 = date(2021,9,15) date2 = date(2022,1,20) difference = date2 - date1 print ( "There are" , difference.days , "days between" , date1 , "and" , date2) Make sure the date is entered in the format of year, month, day . The .days code removes the difference in hours and seconds to just display the number of days difference. There are 127 days between 2021-09-15 and 2022-01-20 Today's Date The program here uses strftime to check the current year, month and day and organise it into the date format . This can then be used together with code similar to the program above to check the number of days between one specific date and the current date. from datetime import date from time import strftime thisyear = int (strftime( "%Y" )) thismonth = int (strftime( "%m" )) thisday = int (strftime( "%d" )) todaysdate = date(thisyear,thismonth,thisday) print ( "The date today is" , todaysdate ) The date today is 2023-09-14 Input a Date The program here shows how to input a date into a format that can then be used by Python to work out the difference between two dates . from datetime import date year = int ( input ( "Enter a year: " ) month = int ( input ( "Enter a month: " ) day = int ( input ( "Enter a day: " ) chosendate = date(year,month,day) print ( "The chosen date is" , chosendate ) Enter a year: 1964 Enter a month: 5 Enter a day: 13 The chosen date is 1964-05-13 Date / Time Task 3 ( Days Alive) Create a program that works out how long the user has been alive for . Use the examples above to automatically make today's date and then allow the user to input their year , month and day of birth. Get Python to work out the difference between today and their date of birth. Example solutions: Enter a year: 1998 Enter a month: 3 Enter a day: 29 You have been alive for 9300 days! Enter a year: 2007 Enter a month: 12 Enter a day: 25 You have been alive for 5742 days! ⬅ 5b - Sleep 5d - Colorama ➡
- Greenfoot Guide #5 | Play Sounds | CSNewbs
Learn how to play sound files in Greenfoot. Part 5 of the Greenfoot Tutorial for the Eduqas / WJEC GCSE 2016 specification. 5. Play Sounds 1. Check the Sounds Folder Greenfoot Tutorial Sound files must be placed the ' sounds ' folder of your Greenfoot project to be used in the game. In the Component 2 exam of the WJEC / Eduqas 2016 specification , an audio file will be placed in the sounds folder already . For this example game you can download the audio clips to the right and paste them into your sounds folder . Watch on YouTube: Click the audio icon to download a zip folder of the two sound files below . Copy the files into the sounds folder of your Greenfoot project . < Part 4 - Remove Objects 2. Add the playSound Method Add the code to play the sound at the same time as when the collectible object is removed . The name of the file and its extension (e.g. .wav or .mp3 ) must be written in speech marks after the playSound method. Part 6 - The Counter >
- Python | 4b - Mathematical Operators | CSNewbs
Learn how to use mathematical operators in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python 4b - Mathematical Operators Modulo Division The modulo operator - the percentage symbol % - will work out the remainder left over when one value is divided by another. print (30 % 6) = 0 30 ÷ 6 = 5, which is a whole number, so there is no remainder and 0 is output . print (30 % 7) = 2 30 ÷ 7 = 4 remainder 2 ; so the remainder is output . You can use modulo with variables too: num1 = 33 num2 = 4 print ( "The remainder is" , num1 % num2) The remainder is 1 = A common use of modulo is to check if a number is odd or even . If a number has no remainder when divided by 2 then it is even . = num = int ( input ( "Enter a number: " )) if num % 2 == 0: print (num, "is even." ) else : print (num , "is odd." ) Enter a number: 400 400 is even. Enter a number: 191 191 is odd. = Modulo Div i sion Task 1 ( Remainder) Ask the user to input a whole number . Use the modulo operator ( % ) to check if there is a remainder when the user's number is divided by 5 . Print the re mainder. Example solution: Enter a number: 123 The remainder when divided by 5 is 3 Modulo Div i sion Task 2 ( Rollercoaster) Use the odd/even program above to help solve this problem: A rollercoaster only lets people on in groups of 4 . Ask the user to input a number for how many people are in their group. Check if that number is directly divisible by 4 using modulo division ( % ). If it is then print “Perfect groups of four!” Else print “You will be split up” . Example solutions: Welcome to the Hyper Coaster! How many in your group? 6 You will be split up! Welcome to the Hyper Coaster! How many in your group? 12 Perfect groups of four! Integer Division Integer division removes any decimal numbers when performing division , leaving just the integer (whole number ). In Python integer division is performed using // . print (20 / 3) print (20 // 3) = 6.666666666666667 6 Integer Div i sion Task 1 ( Integer Division by 5 ) Use an input line with int to ask the user to enter a number . Use integer division ( // ) to divide the number by 5 without keeping any decimal values . Challenge: Improve your solution by altering the print line to be more user friendly . Example solutions: Enter a number: 27 5 Enter a number: 27 5 goes into 27 5 times. Integer Div i sion Task 2 ( Plane Rows) A large plane has 6 seats in each row. Input the number of passengers on the plane and use integer division to work out how many full rows will be filled. Example solution: How many passengers are there in total? 174 There will be 29 full rows on the plane. Exponent (Powers) An exponent is the number of times a value is multiplied by itself , for example 2 = 2 x 2 x 2 = 8 . The symbol to represent an exponent in Python is ** . For example: 4**2 represents 4 which is also 4 x 4 . 3 2 print (4**4) = 256 base = 5 exponent = 4 print (base**exponent) 625 = Exponent Task 1 ( Square Number) Use an input line with int to ask the user to enter a number . Output the square of this number. Example solution: Enter a number: 12 12 squared is 144 Exponent Task 2 ( Custom Exponent) Use an input line with int to ask the user to enter a number, this will be the base . Make another input line with int to ask for the exponent . Use ** between the base and the exponent and print it. Challenge: Make your solution better by including the base and exponent in the print line. Example solutions: Enter the base: 7 Enter the exponent: 3 343 Enter the base: 7 Enter the exponent: 3 7 to the power of 3 is 343 ⬅ 4a - If Statements 4 c - Log ical Operators ➡










