wmaraci reklam

python odevi

2 Mesajlar 955 Okunma
pst.net
wmaraci reklam

Landofire Landofire WM Aracı Kullanıcı
  • Üyelik 30.01.2016
  • Yaş/Cinsiyet 28 / E
  • Meslek Bilgisayar mühendinisi
  • Konum Ankara
  • Ad Soyad V** K**
  • Mesajlar 53
  • Beğeniler 2 / 4
  • Ticaret 0, (%0)
arkadaslar python ogreniyorum da bi python odevinde bu problemi nasil coze bilirim sizce
Problem 1 In this problem, you are expected to write a Python program “problem1.py”.
You should implement a Python function avgFirstThreeDigit() that, when a given list of 3-4 or 5 digit
integers, returns the average of sum of the first three digits of each integers in the reversed order.
Read data from “Integers.txt”, and put them in a list named ListIntegers. Please do not forget use
semicolon as delimiter.
A sample input-output is provided below:
#Read data from file, do not implement list shown below. It is just a sample.
ListIntegers = [18957, 30647, 4653, 1230, 168, 501, 99985, 87965, 534]
output= avgFirstThreeDigit(ListIntegers)
print(output)
simdiden tesekkurler:)

Ek Olarak: yardimci ola bilecek hic kimse yokmu?
 

 

wmaraci
reklam

fmdogancan fmdogancan WM Aracı Kullanıcı
  • Üyelik 22.09.2014
  • Yaş/Cinsiyet 29 / E
  • Meslek Yazılım
  • Konum İstanbul Avrupa
  • Ad Soyad F** D**
  • Mesajlar 46
  • Beğeniler 6 / 10
  • Ticaret 0, (%0)

#-*- coding: utf-8 -*-

def avgFirstThreeDigit(lists):
total = 0
for i in range(3):
total += lists[i]
return total / 3


ListIntegers = [18957, 30647, 4653, 1230, 168, 501, 99985, 87965, 534]
output = avgFirstThreeDigit(ListIntegers)
print output

#dosyadan açarsan
with open('Integers.txt') as f:
for line in f:
ListIntegers = line.split(';')
for i,empty in enumerate(ListIntegers):
if not empty:
del ListIntegers[i]
else:
ListIntegers[i] = int(ListIntegers[i])

output = avgFirstThreeDigit(ListIntegers)
print output


Integers.txt
18957;30647;4653;1230;168;501;99985;87965;534;
 

 

Github: https://github.com/fatihmert | CV: http://fatihmert.dev/        
wmaraci
Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)
Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al