એડવાન્સ પાયથન પ્રોગ્રામિંગ (4321602) - વિન્ટર 2023 સોલ્યુશન
એડવાન્સ પાયથન પ્રોગ્રામિંગ (4321602) વિન્ટર 2023 પરીક્ષા માટેનું સોલ્યુશન ગાઈડ
પ્રશ્ન 1(અ) [3 ગુણ]
ડિક્શનરી શું છે? ઉદાહરણ સાથે સમજાવો.
જવાબ:
ડિક્શનરી એ Python માં key-value pairs નો collection છે જે mutable અને ordered હોય છે.
કોષ્ટક: ડિક્શનરીની વિશેષતાઓ
| વિશેષતા | વર્ણન |
|---|---|
| Mutable | Values ને change કરી શકાય છે |
| Ordered | Python 3.7+ માં insertion order maintain રહે છે |
| Indexed | Keys દ્વારા access કરાય છે |
| No Duplicates | Duplicate keys allow નથી |
Python
- Key-Value Structure: દરેક element માં key અને value હોય છે
- Fast Access: O(1) time complexity માં data access
- Dynamic Size: Runtime માં size વધારી-ઘટાડી શકાય છે
મેમરી ટ્રીક: "Dictionary = Key Value Treasure"
પ્રશ્ન 1(બ) [4 ગુણ]
ટ્યુપલ બિલ્ટ-ઇન ફંકશન અને મેથડોનો વર્ણન કરો.
જવાબ:
ટ્યુપલ માં limited built-in methods છે કારણ કે તે immutable છે.
કોષ્ટક: ટ્યુપલ મેથડો
| મેથડ | વર્ણન | ઉદાહરણ |
|---|---|---|
| count() | Element ની frequency return કરે છે | t.count(5) |
| index() | Element નું first index return કરે છે | t.index('a') |
| len() | ટ્યુપલ નું length return કરે છે | len(t) |
| max() | Maximum value return કરે છે | max(t) |
| min() | Minimum value return કરે છે | min(t) |
Python
- Immutable Nature: Methods ટ્યુપલ ને modify નથી કરતા
- Return Values: બધા methods નવી values return કરે છે
- Type Conversion: tuple() function થી list ને tuple માં convert કરી શકાય
મેમરી ટ્રીક: "Count Index Length Max Min"
પ્રશ્ન 1(ક) [7 ગુણ]
સેટ ઓપરેશન્સ દર્શાવવા માટે પાયથન પ્રોગ્રામ લખો.
જવાબ:
Set operations mathematics ના set theory પર આધારિત છે.
કોષ્ટક: સેટ ઓપરેશન્સ
| ઓપરેશન | Symbol | Method | વર્ણન |
|---|---|---|---|
| Union | | | union() | બન્ને sets ના elements |
| Intersection | & | intersection() | Common elements |
| Difference | - | difference() | First set માંથી second ને minus |
| Symmetric Difference | ^ | symmetric_difference() | Unique elements only |
Python
- Mathematical Operations: Set theory ના operations implement કરે છે
- Efficient Processing: Duplicate elements automatically remove થાય છે
- Boolean Results: Subset/superset operations boolean return કરે છે
મેમરી ટ્રીક: "Union Intersection Difference Symmetric"
પ્રશ્ન 1(ક OR) [7 ગુણ]
ડિક્શનરી ફંકશન અને ઓપરેશન્સ દર્શાવવા માટે પાયથન પ્રોગ્રામ લખો.
જવાબ:
ડિક્શનરી ઓપરેશન્સ data manipulation માટે powerful tools પ્રદાન કરે છે.
કોષ્ટક: ડિક્શનરી મેથડો
| મેથડ | વર્ણન | ઉદાહરણ |
|---|---|---|
| keys() | બધી keys return કરે છે | dict.keys() |
| values() | બધા values return કરે છે | dict.values() |
| items() | Key-value pairs return કરે છે | dict.items() |
| get() | Safe value retrieval | dict.get('key') |
| update() | Dictionary merge કરે છે | dict.update() |
Python
- Dynamic Operations: Runtime માં keys અને values add/remove કરી શકાય
- Safe Access: get() method KeyError prevent કરે છે
- Iteration Support: keys(), values(), items() methods loop માટે useful
મેમરી ટ્રીક: "Get Keys Values Items Update Pop"
પ્રશ્ન 2(અ) [3 ગુણ]
પાયથનમાં ટ્યુપલ અને લિસ્ટ વચ્ચે તફાવત આપો.
જવાબ:
કોષ્ટક: ટ્યુપલ vs લિસ્ટ તુલના
| વિશેષતા | ટ્યુપલ | લિસ્ટ |
|---|---|---|
| Mutability | Immutable (બદલાઈ શકતું નથી) | Mutable (બદલાઈ શકે છે) |
| Syntax | કૌંસ () | ચોરસ કૌંસ [] |
| Performance | ઝડપી | ધીમી |
| Memory | ઓછી memory | વધુ memory |
| Methods | મર્યાદિત (count, index) | ઘણી methods ઉપલબ્ધ |
| Use Case | Fixed data | Dynamic data |
- Immutable Nature: ટ્યુપલ એકવાર create થયા પછી change થઈ શકતું નથી
- Performance: ટ્યુપલ operations લિસ્ટ કરતાં ઝડપી છે
- Memory Efficient: ટ્યુપલ ઓછી memory વાપરે છે
મેમરી ટ્રીક: "Tuple Tight, List Light"
પ્રશ્ન 2(બ) [4 ગુણ]
પાયથનમાં dir() ફંકશન શું છે? ઉદાહરણ સાથે સમજાવો.
જવાબ:
dir() function એ built-in function છે જે object ના attributes અને methods ની list return કરે છે.
કોષ્ટક: dir() ફંકશનની વિશેષતાઓ
| વિશેષતા | વર્ણન |
|---|---|
| Object Inspection | Object ના attributes show કરે છે |
| Method Discovery | Available methods list કરે છે |
| Namespace Exploration | Current namespace ના variables show કરે છે |
| Module Analysis | Module ના contents explore કરે છે |
Python
- Interactive Development: Objects ના capabilities જાણવા માટે useful
- Debugging Tool: Available methods quickly identify કરવા માટે
- Learning Aid: નવી libraries explore કરવા માટે helpful
મેમરી ટ્રીક: "Dir = Directory of Methods"
પ્રશ્ન 2(ક) [7 ગુણ]
સર્કલનો એરિયા અને સિર્કમફેરન્સ શોધવા માટે મોડ્યુલ બનાવો અને બીજા પ્રોગ્રામમાં મોડ્યુલ ઇમ્પોર્ટ કરો.
જવાબ:
Module approach કોડ reusability અને organization સુધારે છે.
ડાયાગ્રામ: મોડ્યુલ સ્ટ્રક્ચર
goat
ફાઇલ 1: circle.py (મોડ્યુલ)
Python
ફાઇલ 2: main.py (મુખ્ય પ્રોગ્રામ)
Python
- Modular Design: Functions ને separate file માં organize કરે છે
- Reusability: Module ને multiple programs માં use કરી શકાય
- Namespace Management: Module prefix થી function access કરાય છે
મેમરી ટ્રીક: "Import Calculate Display"
પ્રશ્ન 2(અ OR) [3 ગુણ]
નેસ્ટેડ ટ્યુપલને ઉદાહરણ સાથે સમજાવો.
જવાબ:
Nested Tuple એ ટ્યુપલ અંદર બીજા tuples હોય છે, જે hierarchical data structure બનાવે છે.
કોષ્ટક: નેસ્ટેડ ટ્યુપલની વિશેષતાઓ
| વિશેષતા | વર્ણન |
|---|---|
| Multi-dimensional | 2D અથવા 3D data structure |
| Immutable | બધા levels પર immutable |
| Indexing | Multiple square brackets વાપરીને access |
| Heterogeneous | અલગ-અલગ data types store કરી શકાય |
Python
- Data Organization: સંબંધિત data ને group કરવા માટે useful
- Immutable Structure: એકવાર create થયા પછી structure change થઈ શકતું નથી
- Efficient Access: Index-based fast access
મેમરી ટ્રીક: "Nested = Tuple Inside Tuple"
પ્રશ્ન 2(બ OR) [4 ગુણ]
PIP શું છે? પાયથન પેકેજને ઇન્સ્ટોલ અને અનઇન્સ્ટોલ કરવા માટે સિન્ટેક્સ લખો.
જવાબ:
PIP (Pip Installs Packages) એ Python package installer છે જે PyPI થી packages download અને install કરે છે.
કોષ્ટક: PIP કમાન્ડો
| કમાન્ડ | સિન્ટેક્સ | વર્ણન |
|---|---|---|
| Install | pip install package_name | Package install કરે છે |
| Uninstall | pip uninstall package_name | Package remove કરે છે |
| List | pip list | Installed packages show કરે છે |
| Show | pip show package_name | Package info display કરે છે |
| Upgrade | pip install --upgrade package_name | Package update કરે છે |
Python
- Package Management: Third-party libraries easily manage કરી શકાય
- Version Control: Specific versions install કરી શકાય
- Dependency Resolution: જરૂરી dependencies automatically install થાય
મેમરી ટ્રીક: "PIP = Package Install Python"
પ્રશ્ન 2(ક OR) [7 ગુણ]
પેકેજ ઇમ્પોર્ટ કરવાની વિવિધ રીતો સમજાવો. મોડ્યુલ અને પેકેજ એકબીજાની સાથે કેવી રીતે જોડાયેલા છે?
જવાબ:
Python માં imports ના વિવિધ ways છે જે code organization અને namespace management માટે મહત્વપૂર્ણ છે.
ડાયાગ્રામ: પેકેજ સ્ટ્રક્ચર
goat
કોષ્ટક: ઇમ્પોર્ટ મેથડો
| મેથડ | સિન્ટેક્સ | ઉપયોગ |
|---|---|---|
| Basic Import | import module | સંપૂર્ણ module name જરૂરી |
| From Import | from module import function | Direct function access |
| Alias Import | import module as alias | Module માટે ટૂંકું નામ |
| Star Import | from module import * | બધા functions import કરવા |
| Package Import | from package import module | Package માંથી import કરવા |
Python
મોડ્યુલ-પેકેજ કનેક્શન:
- Modules: Python code ધરાવતી single .py files
- Packages: __init__.py સાથે multiple modules ધરાવતી directories
- Namespace: Packages hierarchical namespace structure બનાવે છે
- __init__.py: Directory ને package બનાવે છે અને imports control કરે છે
મેમરી ટ્રીક: "Import From As Star Package"
પ્રશ્ન 3(અ) [3 ગુણ]
રનટાઇમ એરર અને સિન્ટેક્સ એરરનું વર્ણન કરો. ઉદાહરણ સાથે સમજાવો.
જવાબ:
કોષ્ટક: એરર પ્રકારોની તુલના
| એરર પ્રકાર | ક્યારે થાય છે | Detection | ઉદાહરણ |
|---|---|---|---|
| Syntax Error | Code parsing time | Execution પહેલાં | Missing colon, brackets |
| Runtime Error | Execution દરમિયાન | Program run કરતી વખતે | Division by zero, file not found |
| Logic Error | હંમેશા | Execution પછી | ખોટી calculation logic |
Python
- Syntax Errors: કોડ run થવા પહેલા જ detect થાય છે
- Runtime Errors: Program execution દરમિયાન થાય છે
- Prevention: Exception handling runtime errors ને handle કરે છે
મેમરી ટ્રીક: "Syntax Before, Runtime During"
પ્રશ્ન 3(બ) [4 ગુણ]
પાયથનમાં Exception હેન્ડલિંગ શું છે? ઉદાહરણ સાથે સમજાવો.
જવાબ:
Exception handling એ mechanism છે જે runtime errors ને gracefully handle કરે છે અને program crash થવાથી prevent કરે છે.
કોષ્ટક: Exception Handling Keywords
| Keyword | હેતુ | વર્ણન |
|---|---|---|
| try | Exception માં થઈ શકે એવો code | Risk code block |
| except | Exception handle કરવા માટે | Error handling block |
| finally | હંમેશા execute થાય | Cleanup code |
| else | Exception ન આવે તો | Success code block |
| raise | Manual exception raise કરવા | Custom error throwing |
Python
- Error Prevention: Program crash થવાથી prevent કરે છે
- Graceful Handling: User-friendly error messages આપે છે
- Resource Management: finally block માં cleanup operations
મેમરી ટ્રીક: "Try Except Finally Else Raise"
પ્રશ્ન 3(ક) [7 ગુણ]
બે સંખ્યાઓના division માટે ફંકશન બનાવો, જો કોઈપણ argument ની value non-integer હોય તો એરર રેઇઝ થાય અથવા જો બીજી argument 0 હોય તો એરર રેઇઝ થાય.
જવાબ:
Custom exception handling function બનાવવું validation અને error control માટે મહત્વપૂર્ણ છે.
ડાયાગ્રામ: ફંકશન ફ્લો
Python
- Input Validation: Arguments ના type અને value check કરે છે
- Custom Errors: Specific exceptions raise કરે છે
- Error Messages: સ્પષ્ટ અને વર્ણનાત્મક error messages
મેમરી ટ્રીક: "Validate Type, Check Zero, Divide Safe"
પ્રશ્ન 4(અ) [3 ગુણ]
ટેક્સ્ટ ફાઇલ અને બાયનરી ફાઇલ વચ્ચેના તફાવત પર પાંચ પોઇન્ટ્સ લખો.
જવાબ:
કોષ્ટક: ટેક્સ્ટ ફાઇલ vs બાયનરી ફાઇલ
| વિશેષતા | ટેક્સ્ટ ફાઇલ | બાયનરી ફાઇલ |
|---|---|---|
| Content | Human-readable characters | Binary data (0s અને 1s) |
| Encoding | Character encoding (UTF-8, ASCII) | કોઈ character encoding નથી |
| Opening Mode | 'r', 'w', 'a' | 'rb', 'wb', 'ab' |
| File Size | સામાન્યતે મોટી | સામાન્યતે નાની |
| Platform | Platform dependent | Platform independent |
Python
- Readability: ટેક્સ્ટ ફાઇલો editor માં read કરી શકાય, બાયનરી ફાઇલો માટે special software જોઈએ
- Portability: બાયનરી ફાઇલો different platforms પર easily transfer થાય
- Processing: ટેક્સ્ટ ફાઇલો string operations માટે, બાયનરી ફાઇલો exact data storage માટે
મેમરી ટ્રીક: "Text Human, Binary Machine"
પ્રશ્ન 4(બ) [4 ગુણ]
ફાઇલમાંથી ડેટા read કરવા માટે પ્રોગ્રામ લખો અને Uppercase કેરેક્ટર અને Lowercase કેરેક્ટરને બે અલગ ફાઇલોમાં separate કરો.
જવાબ:
ફાઇલ processing માં character-based operations સામાન્ય requirements છે.
કોષ્ટક: ફાઇલ ઓપરેશન્સ
| ઓપરેશન | મેથડ | હેતુ |
|---|---|---|
| Read | read() | સંપૂર્ણ ફાઇલ content |
| Write | write() | ફાઇલમાં string લખવા |
| Character Check | isupper(), islower() | Character case detection |
| File Handling | with open() | Safe ફાઇલ operations |
Python
- Character Processing: દરેક character ની case individually check કરાય છે
- File Safety: with statement automatic ફાઇલ closing ensure કરે છે
- Error Handling: ફાઇલ operations માં proper exception handling
મેમરી ટ્રીક: "Read Separate Write"
પ્રશ્ન 4(ક) [7 ગુણ]
dump() અને load() મેથડનું વર્ણન કરો. ઉદાહરણ સાથે સમજાવો.
જવાબ:
dump() અને load() methods pickle module ના part છે જે object serialization માટે વાપરાય છે.
કોષ્ટક: Pickle મેથડો
| મેથડ | હેતુ | File Mode | વર્ણન |
|---|---|---|---|
| dump() | Object ને file માં serialize કરવા | 'wb' | Object ને binary file માં store કરે |
| load() | File માંથી object deserialize કરવા | 'rb' | ફાઇલમાંથી object retrieve કરે |
| dumps() | Bytes માં serialize કરવા | N/A | Object ને bytes માં convert કરે |
| loads() | Bytes માંથી deserialize કરવા | N/A | Bytes માંથી object બનાવે |
ડાયાગ્રામ: Serialization Process
Python
ફાયદા અને મર્યાદાઓ:
Python
- Object Persistence: Python objects ને ફાઇલમાં permanently store કરી શકાય
- Complete State: Object ની complete state including methods preserve થાય છે
- Binary Format: Efficient storage પણ human-readable નથી
મેમરી ટ્રીક: "Dump Store, Load Restore"
પ્રશ્ન 4(અ OR) [3 ગુણ]
ફાઇલ ઓપરેશન માટે પાયથન દ્વારા આપેલ વિવિધ પ્રકારના ફાઇલ modes ની સૂચિ બનાવો અને તેમના ઉપયોગો સમજાવો.
જવાબ:
કોષ્ટક: Python ફાઇલ Modes
| Mode | પ્રકાર | વર્ણન | Pointer Position |
|---|---|---|---|
| 'r' | Text Read | માત્ર read કરવા, ફાઇલ હોવી જરૂરી | શરૂઆત |
| 'w' | Text Write | માત્ર write કરવા, creates/overwrites | શરૂઆત |
| 'a' | Text Append | માત્ર write કરવા, creates if not exist | અંત |
| 'x' | Text Create | નવી ફાઇલ બનાવે, exists હોય તો fail | શરૂઆત |
| 'rb' | Binary Read | Binary data read કરવા | શરૂઆત |
| 'wb' | Binary Write | Binary data write કરવા | શરૂઆત |
| 'ab' | Binary Append | Binary data append કરવા | અંત |
| 'r+' | Text Read/Write | Read અને write, ફાઇલ હોવી જરૂરી | શરૂઆત |
| 'w+' | Text Write/Read | Write અને read, creates/overwrites | શરૂઆત |
Python
- Safety: 'x' mode accidental ફાઇલ overwriting prevent કરે છે
- Efficiency: Binary modes non-text data માટે ઝડપી છે
- Flexibility: Combined modes બંને read અને write operations allow કરે છે
મેમરી ટ્રીક: "Read Write Append Create Binary Plus"
પ્રશ્ન 4(બ OR) [4 ગુણ]
ફાઇલના readline() અને writeline() ફંકશનનું વર્ણન કરો.
જવાબ:
નોંધ: Python માં writeline() ફંકશન અસ્તિત્વમાં નથી. યોગ્ય ફંકશન writelines() છે.
કોષ્ટક: Line-based ફાઇલ ફંકશન્સ
| ફંકશન | હેતુ | Return Type | ઉપયોગ |
|---|---|---|---|
| readline() | એક line read કરવા | String | Sequential line reading |
| readlines() | બધી lines read કરવા | List of strings | Complete ફાઇલ as list |
| writelines() | Multiple lines write કરવા | None | List of strings લખવા |
| write() | Single string write કરવા | Number of chars | Basic writing |
Python
- Sequential Access: readline() sequential manner માં lines read કરે છે
- Memory Efficient: મોટી ફાઇલો માટે readline() memory-efficient છે
- List Operations: writelines() list of strings ને efficiently write કરે છે
મેમરી ટ્રીક: "Read Line, Write Lines"
પ્રશ્ન 4(ક OR) [7 ગુણ]
seek() અને tell() methods ને demonstrate કરવા માટે પાયથન પ્રોગ્રામ લખો.
જવાબ:
seek() અને tell() methods ફાઇલ pointer manipulation માટે વાપરાય છે.
કોષ્ટક: ફાઇલ Pointer મેથડો
| મેથડ | હેતુ | Parameters | Return Value |
|---|---|---|---|
| tell() | Current position | None | Integer (byte position) |
| seek() | Pointer move કરવા | offset, whence | New position |
| whence=0 | શરૂઆતથી | Default | Absolute position |
| whence=1 | Current થી | Relative | Current + offset |
| whence=2 | અંતથી | End relative | End + offset |
ડાયાગ્રામ: ફાઇલ Pointer Movement
goat
Python
- ફાઇલ Navigation: seek() arbitrary position પર move કરવા માટે વાપરાય છે
- Position Tracking: tell() current position track કરવા માટે useful છે
- ફાઇલ Editing: Specific locations પર data modify કરવા માટે જરૂરી
મેમરી ટ્રીક: "Tell Position, Seek Destination"
પ્રશ્ન 5(અ) [3 ગુણ]
ટર્ટલનો ઉપયોગ કરીને circle અને rectangle ના આકાર દોરો અને તેમને લાલ રંગથી ભરો.
જવાબ:
Turtle graphics module માં shapes draw કરવા અને fill કરવા માટે specific methods છે.
કોષ્ટક: Turtle Shape મેથડો
| મેથડ | હેતુ | ઉદાહરણ |
|---|---|---|
| circle() | Circle draw કરવા | turtle.circle(50) |
| forward() | આગળ move કરવા | turtle.forward(100) |
| right() | જમણે turn કરવા | turtle.right(90) |
| begin_fill() | Fill શરૂ કરવા | turtle.begin_fill() |
| end_fill() | Fill સમાપ્ત કરવા | turtle.end_fill() |
| fillcolor() | Fill color set કરવા | turtle.fillcolor("red") |
Python
- Fill Process: begin_fill() અને end_fill() વચ્ચે drawn shape automatically fill થાય છે
- Color Setting: fillcolor() method fill color set કરે છે
- Shape Drawing: Geometric shapes માટે specific turtle movements
મેમરી ટ્રીક: "Begin Fill Draw End"
પ્રશ્ન 5(બ) [4 ગુણ]
ટર્ટલની Direction બદલવાની વિવિધ inbuilt પદ્ધતિઓ સમજાવો.
જવાબ:
કોષ્ટક: Turtle Direction મેથડો
| મેથડ | Parameters | વર્ણન | ઉદાહરણ |
|---|---|---|---|
| right() | angle | Degrees માં જમણે turn કરે છે | turtle.right(90) |
| left() | angle | Degrees માં ડાબે turn કરે છે | turtle.left(45) |
| setheading() | angle | Absolute direction set કરે છે | turtle.setheading(0) |
| towards() | x, y | Coordinates તરફ point કરે છે | turtle.towards(100, 50) |
| home() | none | Center પર return કરે, પૂર્વ તરફ face કરે | turtle.home() |
Python
- Relative Turns: right() અને left() current direction થી relative turn કરે છે
- Absolute Direction: setheading() absolute compass direction set કરે છે
- Smart Pointing: towards() specific coordinates તરફ point કરે છે
મેમરી ટ્રીક: "Right Left Set Towards Home"
પ્રશ્ન 5(ક) [7 ગુણ]
ટર્ટલનો ઉપયોગ કરીને rainbow દોરવા માટે પાયથન પ્રોગ્રામ લખો.
જવાબ:
Rainbow drawing માં multiple colored arcs અને proper positioning જરૂરી છે.
ડાયાગ્રામ: Rainbow Structure
goat
Python
- Color Sequence: ROYGBIV (Red Orange Yellow Green Blue Indigo Violet) નો proper order
- Radius Management: દરેક arc નો radius gradually decrease કરાય છે
- Positioning: Proper positioning માટે penup/pendown અને goto methods
મેમરી ટ્રીક: "ROYGBIV Arc Radius Position"
પ્રશ્ન 5(અ OR) [3 ગુણ]
ટર્ટલ સ્ક્રીનનો ડાયાગ્રામ દોરો અને x અને y કોઓર્ડિનેટ્સના તમામ 4 quadrants સમજાવો.
જવાબ:
ડાયાગ્રામ: Turtle Coordinate System
goat
કોષ્ટક: Coordinate Quadrants
| Quadrant | X Value | Y Value | વર્ણન | ઉદાહરણ |
|---|---|---|---|---|
| I | Positive (+) | Positive (+) | ઉપર-જમણે | (100, 50) |
| II | Negative (-) | Positive (+) | ઉપર-ડાબે | (-100, 50) |
| III | Negative (-) | Negative (-) | નીચે-ડાબે | (-100, -50) |
| IV | Positive (+) | Negative (-) | નીચે-જમણે | (100, -50) |
Python
- Origin: (0,0) screen ના center પર આવેલું છે
- Positive Direction: X-axis જમણે તરફ, Y-axis ઉપર તરફ positive
- Navigation: goto(x, y) method specific coordinates પર move કરે છે
મેમરી ટ્રીક: "Right Up Positive, Left Down Negative"
પ્રશ્ન 5(બ OR) [4 ગુણ]
Background color, title, screensize અને shapesize ને બદલવા માટે વિવિધ ટર્ટલ સ્ક્રીન પદ્ધતિઓનું વર્ણન કરો.
જવાબ:
કોષ્ટક: Turtle Screen મેથડો
| મેથડ | હેતુ | Parameters | ઉદાહરણ |
|---|---|---|---|
| bgcolor() | Background color set કરવા | color name/hex | screen.bgcolor("blue") |
| title() | Window title set કરવા | string | screen.title("My Program") |
| setup() | Screen size set કરવા | width, height | screen.setup(800, 600) |
| screensize() | Canvas size set કરવા | width, height | screen.screensize(400, 300) |
| shapesize() | Turtle size set કરવા | stretch_wid, stretch_len | turtle.shapesize(2, 3) |
Python
- Window vs Canvas: setup() window size, screensize() canvas size control કરે છે
- Color Modes: bgcolor() color names અથવા hex values accept કરે છે
- Shape Scaling: shapesize() turtle appearance ને scale કરે છે
મેમરી ટ્રીક: "Title Background Setup Size Shape"
પ્રશ્ન 5(ક OR) [7 ગુણ]
ટર્ટલનો ઉપયોગ કરીને સ્ટાર, ત્રિકોણ અને અષ્ટકોણ દોરવા માટે પાયથન પ્રોગ્રામ લખો.
જવાબ:
Geometric shapes drawing માં angles અને sides ની proper calculation જરૂરી છે.
કોષ્ટક: Shape Properties
| આકાર | બાજુઓ | External Angle | Internal Angle | Turn Angle |
|---|---|---|---|---|
| ત્રિકોણ | 3 | 120° | 60° | 120° |
| સ્ટાર (5-point) | 5 | 144° | 36° | 144° |
| અષ્ટકોણ | 8 | 45° | 135° | 45° |
ડાયાગ્રામ: Shape Construction
goat
Python
- Angle Calculation: દરેક shape માટે correct turn angles ની calculation જરૂરી
- Fill Technique: begin_fill() અને end_fill() વચ્ચે shape automatically fill થાય
- Mathematical Foundation: Geometry ના principles આધારે shapes construct થાય
મેમરી ટ્રીક: "Triangle 120, Star 144, Octagon 45"